LinuxMCE Forums

General => Users => Topic started by: trippleg on November 17, 2011, 12:57:52 am

Title: A bit of help with some code...
Post by: trippleg on November 17, 2011, 12:57:52 am
I am trying to log an event and assign a template id once a string is found.  I am modifying existing code, but I can not figure it out.  Right now it assigns all devices to template 4, but I only want to assign 0x6B to template 4.  Below is the code.

Code: [Select]
when 0x05 # Climate Control
case $childdatabases[insteonID][0][2..3].hex
when 0x00; @work += 'Broan SMSC080 Exhaust Fan'
when 0x01; @work += 'Simplehomenet EZTherm'
when 0x02; @work += 'Broan SMSC110 Exhaust Fan'
when 0x03; @work += 'Venstar RF Thermostat Module'
when 0x04; @work += 'Simplehomenet EZStat Thermostat'
when 0x6B; @work += 'Venstar RF Thermostat Module'
end
@work += "\t\t4" # Set Template 4

any ideas??

Thanks.

-Gregg
Title: Re: A bit of help with some code...
Post by: JoakimL on November 17, 2011, 08:51:12 am
Looking at http://www.techotopia.com/index.php/The_Ruby_case_Statement it seems the "then" statement should be used.

So the code could look like:
Code: [Select]
case $childdatabases[insteonID][0][2..3].hex @work +=
  when 0x00 then 'Broan SMSC080 Exhaust Fan'
  when 0x01 then 'Simplehomenet EZTherm'
  when 0x02 then 'Broan SMSC110 Exhaust Fan'
  when 0x03 then 'Venstar RF Thermostat Module'
  when 0x04 then 'Simplehomenet EZStat Thermostat'
  when 0x6B then 'Venstar RF Thermostat Module'
end

I'm not a Ruby expert in any way, just a hint... ;-)

/Joakim