diff --git a/bin/.perltidyrc b/bin/.perltidyrc index c689e069a..c63adb806 100644 --- a/bin/.perltidyrc +++ b/bin/.perltidyrc @@ -51,7 +51,7 @@ --look-for-selfloader --maximum-consecutive-blank-lines=1 --maximum-fields-per-table=0 ---maximum-line-length=80 +--maximum-line-length=160 --minimum-space-to-comment=4 --noopening-anonymous-sub-brace-on-new-line --noopening-brace-on-new-line diff --git a/lib/raZberry.pm b/lib/raZberry.pm index 020b24da4..723c8976c 100755 --- a/lib/raZberry.pm +++ b/lib/raZberry.pm @@ -1,12 +1,12 @@ -=head1 B v1.6.1 +=head1 B v2.0 =head2 SYNOPSIS In user code: use raZberry; - $razberry_controller = new raZberry('10.0.1.1'); + $razberry_controller = new raZberry('10.0.1.1',10); $razberry_comm = new raZberry_comm($razberry_controller); $room_fan = new raZberry_dimmer($razberry_controller,'2','force_update'); $room_blind = new raZberry_blind($razberry_controller,'3','digital'); @@ -18,13 +18,13 @@ In user code: $remote_1 = new raZberry_battery($razberry_controller,12); -raZberry(,); +raZberry(,|'push'); raZberry_(,,) In items.mht: -RAZBERRY_CONTROLLER, ip_address, controller_name, group, options +RAZBERRY_CONTROLLER, ip_address, controller_name, group, poll time/'push', options RAZBERRY_DIMMER, device_id, name, group, controller_name, options RAZBERRY_SWITCH, device_id, name, group, controller_name, options RAZBERRY_BLIND, device_id, name, group, controller_name, options @@ -33,11 +33,20 @@ RAZBERRY_THERMOSTAT, device_id, name, group, controller_name, options RAZBERRY_TEMP_SENSOR, device_id, name, group, controller_name, options RAZBERRY_BINARY_SENSOR, device_id, name, group, controller_name, options +RAZBERRY_GENERIC, device_id, name, group, controller_name, options + * Note GENERIC requires the full device ID, ie 2-0-48-1 +RAZBERRY_VOLTAGE, device_id, name, group, controller_name, options + * Note VOLTAGE is a multiattribute device, so device_id can only be the major number + for example: RAZBERRY_CONTROLLER, 10.0.1.1, razberry_controller, zwave RAZBERRY_BLIND, 4, main_blinds, HVAC|zwave, razberry_controller, battery +for specifying controller options; + +RAZBERRY_CONTROLLER, 10.0.1.1, razberry_controller, zwave, ,'user=admin,password=bob' + =head2 DESCRIPTION @@ -54,16 +63,60 @@ the razberry is polled every 5 seconds. Update for local control use the 'niffler' plug in. This saves forcing a local device status every poll. -=head3 SENSOR STATE CHILD OBJECT +=head3 CHILD OBJECTS Each device class will need a child object, as the controller object is just a gateway -to the hardware. Currently the only working device is a razberry_dimmer, and has only -been tested with the leviton fan +to the hardware. There is also a communication object to allow for alerting and monitoring of the razberry controller. -=head2 NOTES +=head2 RaZberry v2 AUTHENTICATION + +Works and tested with v2.0.0. It _should_ also work with v1.7.4. +For later versions, Z_Way has introduced authentication. raZberry v2.0 supports this via two methods: + +1: Enable anonymous authentication: +- Create a room named devices, and assign all ZWay devices to that room +- Create a user named anonymous with role anonymous +- Edit user anonymous and allow access to room devices + +2: Create a new user and give it the admin role. Credentials can be stored in MH either in the mh.private.ini, +or on a per controller basis. + +Then in the controller definition, provide the username and password: +$razberry_controller = new raZberry('10.0.1.1',10,"user=user,password=pwd"); + + +=head2 v2 PUSH or POLL. Only tested in version raZberry 2.3.0 +Using the HTTPGet automation module, this will 'push' a status change to MH rather than the constant polling. Use the following +URL for updating: http://mh:port/SUB;razberry_push(%DEVICE%,%VALUE%) + +If the razberry or mh get out of sync, $controller->poll can be issued to get the latest states. + +Only one razberry controller can be the push source, due to only a single controller object that can be linked to the web service. + +=head2 MH.INI CONFIG PARAMS + +raZberry_timeout +raZberry_poll_seconds +raZberry_user +raZberry_password + +=head2 BUGS + + +=head2 OTHER +http calls can cause pauses. There are a few possible options around this; +- push output to a file and then read the file. This is generally how other modules work. + + +=head2 CHANGELOG +v2.0 +- added in authentication method for razberry 2.1.2+ support +- supports a push method when used in conjunction with the HTTPGet automation module +- displays some controller information at startup + v1.6 - added in digital blinds, battery item (like a remote) @@ -82,35 +135,13 @@ v1.2 - added a check to see if the device is 'dead'. If dead it will attempt a ping for X attempts a Y seconds apart. -OTHER - -Works and tested with v2.0.0. It _should_ also work with v1.7.4. -For later versions, Z_Way has introduced authentication. raZberry will support that at a later time -To get a 2.0+ version to work, anonymous authentication has to be enabled: -- Create a room named devices, and assign all ZWay devices to that room -- Create a user named anonymous with role anonymous -- Edit user anonymous and allow access to room devices - - -http calls can cause pauses. There are a few possible options around this; -- push output to a file and then read the file. This is generally how other modules work. - -config parmas - -raZberry_timeout -raZberry_poll_seconds - -=head2 BUGS - - - -=head2 METHODS =over =cut use strict; +our $push_obj; package raZberry; @@ -118,6 +149,7 @@ use warnings; use LWP::UserAgent; use HTTP::Request::Common qw(POST); +use HTTP::Cookies; use JSON qw(decode_json); #use Data::Dumper; @@ -135,6 +167,7 @@ $zway_system{id}{2} = "2"; my $zway_vdev = "ZWayVDev_zway"; my $zway_suffix = "-0-38"; +our $push_obj = ""; our %rest; $rest{api} = ""; @@ -153,9 +186,10 @@ $rest{ping} = "devices"; $rest{isfailed} = "devices"; $rest{usercode_data} = "devices"; $rest{usercode} = "devices"; +$rest{controller} = "Data/*"; sub new { - my ( $class, $addr, $poll ) = @_; + my ( $class, $addr, $poll, $options ) = @_; my $self = {}; bless $self, $class; $self->{data} = undef; @@ -163,9 +197,16 @@ sub new { $self->{config}->{poll_seconds} = 5; $self->{config}->{poll_seconds} = $main::config_parms{raZberry_poll_seconds} if ( defined $main::config_parms{raZberry_poll_seconds} ); - $self->{config}->{poll_seconds} = $poll if ($poll); - $self->{config}->{poll_seconds} = 1 - if ( $self->{config}->{poll_seconds} < 1 ); + $self->{push} = 0; + + if ( ( defined $poll ) and ( lc $poll eq 'push' ) ) { + $self->{push} = 1; + $self->{config}->{poll_seconds} = 1800; #poll the raZberry every 30 minutes if we are using the push method + } + else { + $self->{config}->{poll_seconds} = $poll if ( defined $poll ); + $self->{config}->{poll_seconds} = 1 if ( $self->{config}->{poll_seconds} < 1 ); + } $self->{updating} = 0; $self->{data}->{retry} = 0; my ( $host, $port ) = ( split /:/, $addr )[ 0, 1 ]; @@ -173,132 +214,183 @@ sub new { $self->{port} = 8083; $self->{port} = $port if ($port); $self->{debug} = 0; - $self->{debug} = $main::Debug{razberry} - if ( defined $main::Debug{razberry} ); - $self->{lastupdate} = undef; - $self->{timeout} = 2; - $self->{timeout} = $main::config_parms{raZberry_timeout} - if ( defined $main::config_parms{raZberry_timeout} ); - $self->{status} = ""; - + ( $self->{debug} ) = ( $options =~ /debug=(\s+)/i ) if ( ( defined $options ) and ( $options =~ m/debug=/i ) ); + $self->{debug} = $main::Debug{raZberry} if ( defined $main::Debug{raZberry} ); + $self->{lastupdate} = undef; + $self->{timeout} = 2; + $self->{timeout} = $main::config_parms{raZberry_timeout} if ( defined $main::config_parms{raZberry_timeout} ); + $self->{status} = ""; + $self->{controller_data} = (); + &main::print_log("[raZberry]: options are $options") if ( ( $self->{debug} ) and ( defined $options ) ); + + $self->{username} = ""; + $options =~ s/username\=/user\=/i if ( defined $options ); + $self->{username} = $main::config_parms{raZberry_user} if ( defined $main::config_parms{raZberry_user} ); + $self->{password} = $main::config_parms{raZberry_password} if ( defined $main::config_parms{raZberry_password} ); + ( $self->{username} ) = ( $options =~ /user\=([a-zA-Z0-9]+)/i ) if ( ( defined $options ) and ( $options =~ m/user\=/i ) ); + ( $self->{password} ) = ( $options =~ /password\=([a-zA-Z0-9]+)/i ) if ( ( defined $options ) and ( $options =~ m/password\=/i ) ); + if ( ( $push_obj eq "" ) and ( $self->{push} ) ) { + &main::print_log("[raZberry]: Push method selected"); + &main::print_log("[raZberry]: The HTTPGet Automation module needs to be installed for push to work"); + &main::print_log('[raZberry]: URL is http://mh:port/SUB;razberry_push(%DEVICE%,%VALUE%)'); + $push_obj = \%{$self}; + } + else { + &main::print_log("[raZberry]: Push method already in use on other object") if ($push_obj); + &main::print_log("[raZberry]: Poll method selected"); + } + if ( $self->{username} ) { + $self->{cookie_jar} = HTTP::Cookies->new( {} ); + $self->login; + } + $self->get_controllerdata; $self->{timer} = new Timer; + $self->poll; $self->start_timer; - &main::print_log("[raZberry] Controller initialized."); + &main::print_log("[raZberry]: Controller Initialization Complete"); return $self; } +sub login { + my ($self) = @_; + + my $ua = new LWP::UserAgent( keep_alive => 1 ); + $ua->timeout( $self->{timeout} ); + $ua->cookie_jar( $self->{cookie_jar} ); + $ua->default_header( 'Accept' => "application/json" ); + $ua->default_header( 'Content-Type' => "application/json" ); + + my $host = $self->{host}; + my $port = $self->{port}; + &main::print_log("[raZberry]: Attempting to authenticate to host $host"); + &main::print_log( "[raZberry]: with user:" . $self->{username} . " password: " . $self->{password} ) if ( $self->{debug} ); + + my $request = HTTP::Request->new( POST => "http://$host:$port/ZAutomation/api/v1/login" ); + my $json = '{"form": true, "login": "' . $self->{username} . '", "password": "' . $self->{password} . '", "keepme": false, "default_ui": 1}'; + $request->content($json); + my $responseObj = $ua->request($request); + $self->{cookie_jar}->extract_cookies($responseObj); + $self->{cookie_jar}->save; + + #print Dumper $self->{cookie_jar}; + #print $json . "\n"; + #print $responseObj->content . "\n--------------------\n"; + if ( $responseObj->code > 400 ) { + $self->{login_success} = 0; + &main::print_log("[raZberry]: Error attempting to authenticate to $host"); + &main::print_log( "[raZberry]: Code is " . $responseObj->code . " and content is " . $responseObj->content ); + } + else { + &main::print_log("[raZberry]: Successful authentication."); + $self->{login_success} = 1; + } +} + +sub get_controllerdata { + my ($self) = @_; + my ( $isSuccessResponse1, $controller_data ) = _get_JSON_data( $self, 'controller' ); + if ($isSuccessResponse1) { + + #print Dumper $controller_data; + $self->{controller_data} = $controller_data->{controller}->{data}; + &main::print_log("[raZberry]: Controller found"); + &main::print_log( "[raZberry]: Chip version:\t\t" . $self->{controller_data}->{ZWaveChip}->{value} ); + &main::print_log( "[raZberry]: Software version:\t" . $self->{controller_data}->{softwareRevisionVersion}->{value} ); + &main::print_log( "[raZberry]: API version:\t\t" . $self->{controller_data}->{APIVersion}->{value} ); + &main::print_log( "[raZberry]: SDK version:\t\t" . $self->{controller_data}->{SDK}->{value} ); + } + else { + &main::print_log( "[raZberry]: Problem connecting to controller " . $self->{host} ); + } +} + sub poll { my ($self) = @_; - &main::print_log("[raZberry] Polling initiated") if ( $self->{debug} ); + &main::print_log("[raZberry]: Polling initiated") if ( $self->{debug} ); my $cmd = ""; $cmd = "?since=" . $self->{lastupdate} if ( defined $self->{lastupdate} ); - &main::print_log("[raZberry] cmd=$cmd") if ( $self->{debug} > 1 ); + &main::print_log("[raZberry]: cmd=$cmd") if ( $self->{debug} > 1 ); for my $dev ( keys %{ $self->{data}->{force_update} } ) { - &main::print_log( - "[raZberry] Forcing update to device $dev to account for local changes" - ) if ( $self->{debug} ); + &main::print_log("[raZberry]: Forcing update to device $dev to account for local changes") if ( $self->{debug} ); $self->update_dev($dev); } for my $dev ( keys %{ $self->{data}->{ping} } ) { - &main::print_log("[raZberry] Keep_alive: Pinging device $dev...") - ; # if ($self->{debug}); - &main::print_log("[raZberry] ping_dev $dev"); # if ($self->{debug}); - #$self->ping_dev($dev); + &main::print_log("[raZberry]: Keep_alive: Pinging device $dev..."); # if ($self->{debug}); + &main::print_log("[raZberry]: ping_dev $dev"); # if ($self->{debug}); + #$self->ping_dev($dev); } - my ( $isSuccessResponse1, $devices ) = - _get_JSON_data( $self, 'devices', $cmd ); + my ( $isSuccessResponse1, $devices ) = _get_JSON_data( $self, 'devices', $cmd ); # print Dumper $devices if ( $self->{debug} > 1 ); if ($isSuccessResponse1) { $self->{lastupdate} = $devices->{data}->{updateTime}; foreach my $item ( @{ $devices->{data}->{devices} } ) { - &main::print_log( "[raZberry] Found:" - . $item->{id} - . " with level " - . $item->{metrics}->{level} - . " and updated " - . $item->{updateTime} - . "." ) + &main::print_log( "[raZberry]: Found:" . $item->{id} . " with level " . $item->{metrics}->{level} . " and updated " . $item->{updateTime} . "." ) if ( $self->{debug} ); #my ($id) = ( split /_/, $item->{id} )[2]; - my ($id) = - ( split /_/, $item->{id} )[-1]; #always just get the last element + my ($id) = ( split /_/, $item->{id} )[-1]; #always just get the last element print "id=$id\n" if ( $self->{debug} > 1 ); my $battery_dev = 0; $battery_dev = 1 if ( $id =~ m/-0-128$/ ); - if ($battery_dev) { #for a battery, set a different object - $self->{data}->{devices}->{$id}->{battery_level} = - $item->{metrics}->{level}; + my $voltage_dev = 0; + $voltage_dev = 1 if ( $id =~ m/-0-50-\d$/ ); + if ($battery_dev) { #for a battery, set a different object + $self->{data}->{devices}->{$id}->{battery_level} = $item->{metrics}->{level}; + } + elsif ($voltage_dev) { + &main::print_log("[raZberry]: Voltage Device found"); } else { - $self->{data}->{devices}->{$id}->{level} = - $item->{metrics}->{level}; + $self->{data}->{devices}->{$id}->{level} = $item->{metrics}->{level}; } $self->{data}->{devices}->{$id}->{updateTime} = $item->{updateTime}; $self->{data}->{devices}->{$id}->{devicetype} = $item->{deviceType}; $self->{data}->{devices}->{$id}->{location} = $item->{location}; - $self->{data}->{devices}->{$id}->{title} = - $item->{metrics}->{title}; - $self->{data}->{devices}->{$id}->{icon} = $item->{metrics}->{icon}; + $self->{data}->{devices}->{$id}->{title} = $item->{metrics}->{title}; + $self->{data}->{devices}->{$id}->{icon} = $item->{metrics}->{icon}; #thermostat data items - $self->{data}->{devices}->{$id}->{units} = - $item->{metrics}->{scaleTitle} + $self->{data}->{devices}->{$id}->{units} = $item->{metrics}->{scaleTitle} if ( defined $item->{metrics}->{scaleTitle} ); - $self->{data}->{devices}->{$id}->{temp_min} = - $item->{metrics}->{min} + $self->{data}->{devices}->{$id}->{temp_min} = $item->{metrics}->{min} if ( defined $item->{metrics}->{min} ); - $self->{data}->{devices}->{$id}->{temp_max} = - $item->{metrics}->{max} + $self->{data}->{devices}->{$id}->{temp_max} = $item->{metrics}->{max} if ( defined $item->{metrics}->{max} ); $self->{status} = "online"; if ( defined $self->{child_object}->{$id} ) { if ($battery_dev) { - &main::print_log( - "[raZberry] Child object detected: Battery Level:[" + &main::print_log( "[raZberry]: Child object detected: Battery Level:[" . $item->{metrics}->{level} . "] Child Level:[" . $self->{child_object}->{$id}->battery_level() . "]" ) if ( $self->{debug} > 1 ); - $self->{child_object}->{$id} - ->update_data( $self->{data}->{devices}->{$id} ) - ; #be able to push other data to objects for actions + $self->{child_object}->{$id}->update_data( $self->{data}->{devices}->{$id} ); #be able to push other data to objects for actions } else { - &main::print_log( - "[raZberry] Child object detected: Controller Level:[" + &main::print_log( "[raZberry]: Child object detected: Controller Level:[" . $item->{metrics}->{level} . "] Child Level:[" . $self->{child_object}->{$id}->level() . "]" ) if ( $self->{debug} > 1 ); - $self->{child_object}->{$id} - ->set( $item->{metrics}->{level}, 'poll' ) - if ( - ( - $self->{child_object}->{$id}->level() ne - $item->{metrics}->{level} - ) - and !( $id =~ m/-0-128$/ ) - ); - $self->{child_object}->{$id} - ->update_data( $self->{data}->{devices}->{$id} ) - ; #be able to push other data to objects for actions + $self->{child_object}->{$id}->set( $item->{metrics}->{level}, 'poll' ) + if ( ( $self->{child_object}->{$id}->level() ne $item->{metrics}->{level} ) + and !( $id =~ m/-0-128$/ ) ); + $self->{child_object}->{$id}->update_data( $self->{data}->{devices}->{$id} ); #be able to push other data to objects for actions } } } } else { - &main::print_log( - "[raZberry] Problem retrieving data from " . $self->{host} ); + &main::print_log( "[raZberry]: Problem retrieving data from " . $self->{host} ); $self->{data}->{retry}++; return ('0'); } @@ -308,7 +400,7 @@ sub poll { sub set_dev { my ( $self, $device, $mode ) = @_; - &main::print_log("[raZberry] Setting $device to $mode") + &main::print_log("[raZberry]: Setting $device to $mode") if ( $self->{debug} ); my $cmd; @@ -316,13 +408,11 @@ sub set_dev { if ( defined $rest{$action} ) { $cmd = "/$zway_vdev" . "_" . $device . "/$rest{$action}"; $cmd .= "$lvl" if $lvl; - &main::print_log("[raZberry] sending command $cmd") + &main::print_log("[raZberry]: sending command $cmd") if ( $self->{debug} > 1 ); - my ( $isSuccessResponse1, $status ) = - _get_JSON_data( $self, 'devices', $cmd ); + my ( $isSuccessResponse1, $status ) = _get_JSON_data( $self, 'devices', $cmd ); unless ($isSuccessResponse1) { - &main::print_log( - "[raZberry] Problem retrieving data from " . $self->{host} ); + &main::print_log( "[raZberry]: Problem retrieving data from " . $self->{host} ); return ('0'); } @@ -336,15 +426,14 @@ sub ping_dev { #curl --globoff "http://mhip:8083/ZWaveAPI/Run/devices[x].SendNoOperation()" my ( $devid, $instance, $class ) = ( split /-/, $device )[ 0, 1, 2 ]; - &main::print_log("[raZberry] Pinging device $device ($devid)...") + &main::print_log("[raZberry]: Pinging device $device ($devid)...") if ( $self->{debug} ); my $cmd; $cmd = "%5B" . $devid . "%5D.SendNoOperation()"; &main::print_log("ping cmd=$cmd"); # if ($self->{debug} > 1); my ( $isSuccessResponse0, $status ) = _get_JSON_data( $self, 'ping', $cmd ); unless ($isSuccessResponse0) { - &main::print_log( - "[raZberry] Error: Problem retrieving data from " . $self->{host} ); + &main::print_log( "[raZberry]: Error: Problem retrieving data from " . $self->{host} ); $self->{data}->{retry}++; return ('0'); } @@ -356,17 +445,15 @@ sub isfailed_dev { #"http://mhip:8083/ZWaveAPI/Run/devices[x].data.isFailed.value" my ( $self, $device ) = @_; my ( $devid, $instance, $class ) = ( split /-/, $device )[ 0, 1, 2 ]; - &main::print_log("[raZberry] Checking $device ($devid)...") + &main::print_log("[raZberry]: Checking $device ($devid)...") if ( $self->{debug} ); my $cmd; $cmd = "%5B" . $devid . "%5D.data.isFailed.value"; &main::print_log("isFailed cmd=$cmd"); # if ($self->{debug} > 1); - my ( $isSuccessResponse0, $status ) = - _get_JSON_data( $self, 'isfailed', $cmd ); + my ( $isSuccessResponse0, $status ) = _get_JSON_data( $self, 'isfailed', $cmd ); unless ($isSuccessResponse0) { - &main::print_log( - "[raZberry] Error: Problem retrieving data from " . $self->{host} ); + &main::print_log( "[raZberry]: Error: Problem retrieving data from " . $self->{host} ); $self->{data}->{retry}++; return ('error'); } @@ -377,21 +464,13 @@ sub update_dev { my ( $self, $device ) = @_; my $cmd; my ( $devid, $instance, $class ) = ( split /-/, $device )[ 0, 1, 2 ]; - $cmd = "%5B" - . $devid - . "%5D.instances%5B" - . $instance - . "%5D.commandClasses%5B" - . $class - . "%5D.Get()"; - &main::print_log("[raZberry] Getting local state from $device ($devid)...") + $cmd = "%5B" . $devid . "%5D.instances%5B" . $instance . "%5D.commandClasses%5B" . $class . "%5D.Get()"; + &main::print_log("[raZberry]: Getting local state from $device ($devid)...") if ( $self->{debug} ); &main::print_log("cmd=$cmd") if ( $self->{debug} > 1 ); - my ( $isSuccessResponse0, $status ) = - _get_JSON_data( $self, 'force_update', $cmd ); + my ( $isSuccessResponse0, $status ) = _get_JSON_data( $self, 'force_update', $cmd ); unless ($isSuccessResponse0) { - &main::print_log( - "[raZberry] Error: Problem retrieving data from " . $self->{host} ); + &main::print_log( "[raZberry]: Error: Problem retrieving data from " . $self->{host} ); $self->{data}->{retry}++; return ('0'); } @@ -407,7 +486,7 @@ sub _get_JSON_data { $self->{updating} = 1; my $ua = new LWP::UserAgent( keep_alive => 1 ); $ua->timeout( $self->{timeout} ); - + $ua->cookie_jar( $self->{cookie_jar} ) if ( $self->{username} ); my $host = $self->{host}; my $port = $self->{port}; my $params = ""; @@ -419,33 +498,39 @@ sub _get_JSON_data { or ( $mode eq "isfailed" ) or ( $mode eq "usercode" ) or ( $mode eq "usercode_data" ) ); - &main::print_log( - "[raZberry] contacting http://$host:$port/$method/$rest{$mode}$params" - ) if ( $self->{debug} ); + $method = "ZWaveAPI" if ( $mode eq "controller" ); + &main::print_log("[raZberry]: contacting http://$host:$port/$method/$rest{$mode}$params") if ( $self->{debug} ); - my $request = - HTTP::Request->new( - GET => "http://$host:$port/$method/$rest{$mode}$params" ); + my $request = HTTP::Request->new( GET => "http://$host:$port/$method/$rest{$mode}$params" ); $request->content_type("application/x-www-form-urlencoded"); - my $responseObj = $ua->request($request); - print $responseObj->content . "\n--------------------\n" - if ( $self->{debug} > 1 ); + #if unauthenticated, then try another login attempt. + my $connect_req = 0; + my $responseObj; + my $responseCode; + do { + $responseObj = $ua->request($request); + print $responseObj->content . "\n--------------------\n" if ( $self->{debug} > 1 ); + $responseCode = $responseObj->code; + print 'Response code: ' . $responseCode . "\n" if ( $self->{debug} > 1 ); + if ( ( $responseCode == 401 ) and ( !$connect_req ) ) { + &main::print_log("[raZberry]: ReAuthenticating..."); + $self->login; + $connect_req = 1; + } + else { + $connect_req = 2; + } + } until ( $connect_req == 2 ); - my $responseCode = $responseObj->code; - print 'Response code: ' . $responseCode . "\n" - if ( $self->{debug} > 1 ); my $isSuccessResponse = $responseCode < 400; $self->{updating} = 0; if ( !$isSuccessResponse ) { - &main::print_log( - "[raZberry] Warning, failed to get data. Response code $responseCode" - ); + &main::print_log("[raZberry]: Warning, failed to get data. Response code $responseCode"); if ( defined $self->{child_object}->{comm} ) { if ( $self->{status} eq "online" ) { $self->{status} = "offline"; - main::print_log - "[raZberry] Communication Tracking object found. Updating from " + main::print_log "[raZberry]: Communication Tracking object found. Updating from " . $self->{child_object}->{comm}->state() . " to offline..." if ( $self->{loglevel} ); @@ -457,10 +542,7 @@ sub _get_JSON_data { if ( defined $self->{child_object}->{comm} ) { if ( $self->{status} eq "offline" ) { $self->{status} = "online"; - main::print_log - "[raZberry] Communication Tracking object found. Updating from " - . $self->{child_object}->{comm}->state() - . " to online..." + main::print_log "[raZberry]: Communication Tracking object found. Updating from " . $self->{child_object}->{comm}->state() . " to online..." if ( $self->{loglevel} ); $self->{child_object}->{comm}->set( "online", 'poll' ); } @@ -468,28 +550,23 @@ sub _get_JSON_data { return ('1') if ( ( $mode eq "force_update" ) or ( $mode eq "ping" ) - or ( $mode eq "usercode" ) ) - ; #these come backs as nulls which crashes JSON::XS, so just return. + or ( $mode eq "usercode" ) ); #these come backs as nulls which crashes JSON::XS, so just return. return ( $responseObj->content ) if ( $mode eq "isfailed" ); # my $response = JSON::XS->new->decode( $responseObj->content ); my $response; eval { - $response = decode_json( $responseObj->content ) - ; #HP, wrap this in eval to prevent MH crashes + $response = decode_json( $responseObj->content ); #HP, wrap this in eval to prevent MH crashes }; if ($@) { - &main::print_log( - "[raZberry]: WARNING: decode_json failed for returned data"); + &main::print_log("[raZberry]: WARNING: decode_json failed for returned data"); return ( "0", "" ); } return ( $isSuccessResponse, $response ) } else { - &main::print_log( - "[raZberry] Warning, not fetching data due to operation in progress" - ); + &main::print_log("[raZberry]: Warning, not fetching data due to operation in progress"); return ('0'); } } @@ -503,8 +580,7 @@ sub stop_timer { sub start_timer { my ($self) = @_; - $self->{timer}->set( $self->{config}->{poll_seconds}, - sub { &raZberry::poll($self) }, -1 ); + $self->{timer}->set( $self->{config}->{poll_seconds}, sub { &raZberry::poll($self) }, -1 ); } sub display_all_devices { @@ -514,10 +590,8 @@ sub display_all_devices { print "RaZberry Device $id\n"; print "\t level:\t\t $self->{data}->{devices}->{$id}->{level}\n"; - print "\t updateTime:\t " - . localtime( $self->{data}->{devices}->{$id}->{updateTime} ) . "\n"; - print - "\t deviceType:\t $self->{data}->{devices}->{$id}->{devicetype}\n"; + print "\t updateTime:\t " . localtime( $self->{data}->{devices}->{$id}->{updateTime} ) . "\n"; + print "\t deviceType:\t $self->{data}->{devices}->{$id}->{devicetype}\n"; print "\t location:\t $self->{data}->{devices}->{$id}->{location}\n"; print "\t title:\t\t $self->{data}->{devices}->{$id}->{title}\n"; print "\t icon:\t\t $self->{data}->{devices}->{$id}->{icon}\n\n"; @@ -534,8 +608,7 @@ sub get_dev_status { } else { - &main::print_log( - "[raZberry] Warning, unable to get status of device $id"); + &main::print_log("[raZberry]: Warning, unable to get status of device $id"); return 0; } @@ -544,8 +617,7 @@ sub get_dev_status { sub register { my ( $self, $object, $dev, $options ) = @_; if ( lc $dev eq 'comm' ) { - &main::print_log( - "[raZberry] Registering Communication object to controller"); + &main::print_log("[raZberry]: Registering Communication object to controller"); $self->{child_object}->{'comm'} = $object; } else { @@ -553,27 +625,59 @@ sub register { my $type = $object->{type}; $type = "Digital " . $type if ( ( defined $options ) and ( $options =~ m/digital/ ) ); - &main::print_log( "[raZberry] Registering " - . $type - . " Device ID $dev to controller" ); + &main::print_log( "[raZberry]: Registering " . $type . " Device ID $dev to controller" ); $self->{child_object}->{$dev} = $object; if ( defined $options ) { if ( $options =~ m/force_update/ ) { $self->{data}->{force_update}->{$dev} = 1; - &main::print_log( - "[raZberry] Forcing Controller to contact Device $dev at each poll" - ); + &main::print_log("[raZberry]: Forcing Controller to contact Device $dev at each poll"); } if ( $options =~ m/keep_alive/ ) { $self->{data}->{ping}->{$dev} = 1; - &main::print_log( - "[raZberry] Forcing Controller to ping Device $dev at each poll" - ); + &main::print_log("[raZberry]: Forcing Controller to ping Device $dev at each poll"); } } } } +sub main::razberry_push { + my ( $dev, $level ) = @_; + + my ($id) = ( split /_/, $dev )[-1]; #always just get the last element + + #Filter out some non-items + return if ( ( $dev =~ m/^InfoWidget_/ ) + or ( $dev =~ m/^BatteryPolling_/ ) ); + + &main::print_log("[raZberry]: HTTP Push update received for device: $dev, id: $id and level: $level"); + + #my $obj = &main::get_object_by_name($object); + if ( $push_obj eq "" ) { + &main::print_log("[raZberry]: ERROR, Push control not enabled on this controller."); + + } + elsif ( $dev =~ m/^ZWayVDev_zway_/ ) { + if ( defined $push_obj->{child_object}->{$id} ) { + if ( $dev =~ m/\-0\-\50\-\d$/ ) { + ( my $subdev ) = ( $dev =~ /\-0\-50\-(\d)$/ ); + &main::print_log( '[raZberry]: Calling $push_obj->{child_object}->{' . $id . '}->set_level( ' . $level . ", $subdev );" ); + } + else { + &main::print_log( '[raZberry]: Calling $push_obj->{child_object}->{' . $id . '}->set( ' . $level . ", 'push' );" ); + $push_obj->{child_object}->{$id}->set( $level, 'push' ); + } + } + else { + &main::print_log("[raZberry]: ERROR, child object id $id not found!"); + } + + } + else { + &main::print_log("[raZberry]: ERROR, only ZWayVDev devices supported for push"); + } + +} + package raZberry_dimmer; @raZberry_dimmer::ISA = ('Generic_Item'); @@ -583,11 +687,7 @@ sub new { my $self = {}; bless $self, $class; - push( - @{ $$self{states} }, - 'off', 'low', 'med', 'high', 'on', '10%', '20%', - '30%', '40%', '50%', '60%', '70%', '80%', '90%' - ); + push( @{ $$self{states} }, 'off', 'low', 'med', 'high', 'on', '10%', '20%', '30%', '40%', '50%', '60%', '70%', '80%', '90%' ); $$self{master_object} = $object; $devid = $devid . $zway_suffix if ( $devid =~ m/^\d+$/ ); @@ -605,7 +705,7 @@ sub new { sub set { my ( $self, $p_state, $p_setby ) = @_; - if ( $p_setby eq 'poll' ) { + if ( defined $p_setby && ( ( $p_setby eq 'poll' ) or ( $p_setby eq 'push' ) ) ) { $self->{level} = $p_state; my $n_state; if ( $p_state == 100 ) { @@ -626,9 +726,7 @@ sub set { else { $n_state .= "$p_state%"; } - main::print_log( - "[raZberry_dimmer] Setting value to $n_state. Level is " - . $self->{level} ) + main::print_log( "[raZberry_dimmer] Setting value to $n_state. Level is " . $self->{level} ) if ( $self->{debug} ); $self->SUPER::set($n_state); @@ -651,8 +749,7 @@ sub set { $$self{master_object}->set_dev( $$self{devid}, "level=$n_state" ); } else { - main::print_log( - "[raZberry_dimmer] Error. Unknown set state $p_state"); + main::print_log("[raZberry_dimmer] Error. Unknown set state $p_state"); } } } @@ -706,7 +803,7 @@ sub new { sub set { my ( $self, $p_state, $p_setby ) = @_; - if ( $p_setby eq 'poll' ) { + if ( defined $p_setby && ( ( $p_setby eq 'poll' ) or ( $p_setby eq 'push' ) ) ) { if ( lc $p_state eq "on" ) { $self->{level} = 100; } @@ -714,9 +811,7 @@ sub set { $self->{level} = 0; } - main::print_log( - "[raZberry_switch] Setting value to $p_state. Level is " - . $self->{level} ) + main::print_log( "[raZberry_switch] Setting value to $p_state. Level is " . $self->{level} ) if ( $self->{debug} ); $self->SUPER::set($p_state); } @@ -725,8 +820,7 @@ sub set { $$self{master_object}->set_dev( $$self{devid}, $p_state ); } else { - main::print_log( - "[raZberry_switch] Error. Unknown set state $p_state"); + main::print_log("[raZberry_switch] Error. Unknown set state $p_state"); } } } @@ -793,11 +887,7 @@ sub new { $self->{digital} = 1 if ( ( defined $options ) and ( $options =~ m/digital/i ) ); if ( $self->{digital} ) { - push( - @{ $$self{states} }, - 'down', '10%', '20%', '30%', '40%', '50%', - '60%', '70%', '80%', '90%', 'up' - ); + push( @{ $$self{states} }, 'down', '10%', '20%', '30%', '40%', '50%', '60%', '70%', '80%', '90%', 'up' ); } else { push( @{ $$self{states} }, 'down', 'stop', 'up' ); @@ -824,7 +914,7 @@ sub new { sub set { my ( $self, $p_state, $p_setby ) = @_; - if ( defined $p_setby && $p_setby eq 'poll' ) { + if ( defined $p_setby && ( ( $p_setby eq 'poll' ) or ( $p_setby eq 'push' ) ) ) { $self->{level} = $p_state; my $n_state; if ( $p_state == 0 ) { @@ -845,8 +935,7 @@ sub set { } # stop level? - main::print_log( "[raZberry_blind] Setting value to $n_state. Level is " - . $self->{level} ) + main::print_log( "[raZberry_blind] Setting value to $n_state. Level is " . $self->{level} ) if ( $self->{debug} ); $self->SUPER::set($n_state); } @@ -860,12 +949,10 @@ sub set { } elsif ( ( $p_state eq "100%" ) or ( $p_state =~ m/^\d{1,2}\%$/ ) ) { my ($n_state) = ( $p_state =~ /(\d+)%/ ); - $$self{master_object} - ->set_dev( $$self{devid}, "level=$n_state" ); + $$self{master_object}->set_dev( $$self{devid}, "level=$n_state" ); } else { - main::print_log( - "[raZberry_blind] Error. Unknown set state $p_state"); + main::print_log("[raZberry_blind] Error. Unknown set state $p_state"); } } elsif (( lc $p_state eq "up" ) @@ -875,8 +962,7 @@ sub set { $$self{master_object}->set_dev( $$self{devid}, $p_state ); } else { - main::print_log( - "[raZberry_blind] Error. Unknown set state $p_state"); + main::print_log("[raZberry_blind] Error. Unknown set state $p_state"); } } } @@ -902,9 +988,7 @@ sub isfailed { sub update_data { my ( $self, $data ) = @_; if ( defined $data->{battery_level} ) { - &main::print_log( "[raZberry_blind] Setting battery value to " - . $data->{battery_level} - . "." ) + &main::print_log( "[raZberry_blind] Setting battery value to " . $data->{battery_level} . "." ) if ( $self->{debug} ); $self->{battery_level} = $data->{battery_level}; } @@ -913,20 +997,15 @@ sub update_data { sub battery_check { my ($self) = @_; unless ( $self->{battery} ) { - main::print_log( - "[raZberry_blind] ERROR, battery option not defined on this object" - ); + main::print_log("[raZberry_blind] ERROR, battery option not defined on this object"); return; } if ( $self->{battery_level} eq "" ) { - main::print_log( - "[raZberry_blind] INFO Battery level currently undefined"); + main::print_log("[raZberry_blind] INFO Battery level currently undefined"); return; } - main::print_log( "[raZberry_blind] INFO Battery currently at " - . $self->{battery_level} - . "%" ); + main::print_log( "[raZberry_blind] INFO Battery currently at " . $self->{battery_level} . "%" ); if ( ( $self->{battery_level} < 30 ) and ( $self->{battery_alert} == 0 ) ) { $self->{battery_alert} = 1; main::speak("Warning, Zwave blind battery has less than 30% charge"); @@ -939,8 +1018,7 @@ sub battery_check { sub _battery_timer { my ($self) = @_; - $self->{battery_timer}->set( $self->{battery_poll_seconds}, - sub { &raZberry_blind::battery_check($self) }, -1 ); + $self->{battery_timer}->set( $self->{battery_poll_seconds}, sub { &raZberry_blind::battery_check($self) }, -1 ); } sub battery_level { @@ -999,11 +1077,8 @@ sub set { $map_states{locked} = "close"; $map_states{unlocked} = "open"; - if ( $p_setby eq 'poll' ) { - main::print_log( "[raZberry_lock] Setting value to $p_state: " - . $map_states{$p_state} - . ". Battery Level is " - . $self->{battery_level} ) + if ( defined $p_setby && ( ( $p_setby eq 'poll' ) or ( $p_setby eq 'push' ) ) ) { + main::print_log( "[raZberry_lock] Setting value to $p_state: " . $map_states{$p_state} . ". Battery Level is " . $self->{battery_level} ) if ( $self->{debug} ); if ( ( $p_state eq "open" ) or ( $p_state eq "close" ) ) { $self->SUPER::set( $map_states{$p_state} ); @@ -1012,19 +1087,16 @@ sub set { $self->{level} = $p_state; } else { - main::print_log( - "[raZberry_lock] Unknown value $p_state in poll set"); + main::print_log("[raZberry_lock] Unknown value $p_state in poll set"); } } else { if ( ( lc $p_state eq "locked" ) or ( lc $p_state eq "unlocked" ) ) { - $$self{master_object} - ->set_dev( $$self{devid}, $map_states{$p_state} ); + $$self{master_object}->set_dev( $$self{devid}, $map_states{$p_state} ); } else { - main::print_log( "[raZberry_lock] Error. Unknown set state " - . $map_states{$p_state} ); + main::print_log( "[raZberry_lock] Error. Unknown set state " . $map_states{$p_state} ); } } } @@ -1056,9 +1128,7 @@ sub isfailed { sub update_data { my ( $self, $data ) = @_; if ( defined $data->{battery_level} ) { - &main::print_log( "[raZberry_lock] Setting battery value to " - . $data->{battery_level} - . "." ) + &main::print_log( "[raZberry_lock] Setting battery value to " . $data->{battery_level} . "." ) if ( $self->{debug} ); $self->{battery_level} = $data->{battery_level}; } @@ -1067,13 +1137,10 @@ sub update_data { sub battery_check { my ($self) = @_; if ( $self->{battery_level} eq "" ) { - &main::print_log( - "[raZberry_lock] INFO Battery level currently undefined"); + &main::print_log("[raZberry_lock] INFO Battery level currently undefined"); return; } - &main::print_log( "[raZberry_lock] INFO Battery currently at " - . $self->{battery_level} - . "%" ); + &main::print_log( "[raZberry_lock] INFO Battery currently at " . $self->{battery_level} . "%" ); if ( ( $self->{battery_level} < 30 ) and ( $self->{battery_alert} == 0 ) ) { $self->{battery_alert} = 1; &main::speak("Warning, Zwave lock battery has less than 30% charge"); @@ -1090,8 +1157,7 @@ sub enable_user { $status = $self->_control_user( $userid, $code, "1" ); #delay for the lock to process the code and then read in the users - main::eval_with_timer( sub { &raZberry_lock::_update_users($self) }, - $self->{user_data_delay} ); + main::eval_with_timer( sub { &raZberry_lock::_update_users($self) }, $self->{user_data_delay} ); return ($status); } @@ -1104,8 +1170,7 @@ sub disable_user { $status = $self->_control_user( $userid, $code, "0" ); #delay for the lock to process the code and then read in the users - main::eval_with_timer( sub { &raZberry_lock::_update_users($self) }, - $self->{user_data_delay} ); + main::eval_with_timer( sub { &raZberry_lock::_update_users($self) }, $self->{user_data_delay} ); return ($status); } @@ -1132,8 +1197,7 @@ sub print_users { sub _battery_timer { my ($self) = @_; - $self->{battery_timer}->set( $self->{battery_poll_seconds}, - sub { &raZberry_lock::battery_check($self) }, -1 ); + $self->{battery_timer}->set( $self->{battery_poll_seconds}, sub { &raZberry_lock::battery_check($self) }, -1 ); } sub _control_user { @@ -1143,20 +1207,13 @@ sub _control_user { my $cmd; my ( $devid, $instance, $class ) = ( split /-/, $self->{devid} )[ 0, 1, 2 ]; - $cmd = "%5B" - . $devid - . "%5D.UserCode.Set(" - . $userid . "," - . $code . "," - . $control . ")"; - &main::print_log("[raZberry] Enabling usercodes $userid ($devid)...") + $cmd = "%5B" . $devid . "%5D.UserCode.Set(" . $userid . "," . $code . "," . $control . ")"; + &main::print_log("[raZberry]: Enabling usercodes $userid ($devid)...") if ( $self->{debug} ); &main::print_log("cmd=$cmd") if ( $self->{debug} > 1 ); - my ( $isSuccessResponse0, $status ) = - &raZberry::_get_JSON_data( $self->{master_object}, 'usercode', $cmd ); + my ( $isSuccessResponse0, $status ) = &raZberry::_get_JSON_data( $self->{master_object}, 'usercode', $cmd ); unless ($isSuccessResponse0) { - &main::print_log( - "[raZberry] Error: Problem retrieving data from " . $self->{host} ); + &main::print_log( "[raZberry]: Error: Problem retrieving data from " . $self->{host} ); $self->{data}->{retry}++; return ('0'); } @@ -1169,27 +1226,22 @@ sub _update_users { my $cmd; my ( $devid, $instance, $class ) = ( split /-/, $self->{devid} )[ 0, 1, 2 ]; $cmd = "%5B" . $devid . "%5D.UserCode.Get()"; - &main::print_log("[raZberry] Getting local usercodes ($devid)...") + &main::print_log("[raZberry]: Getting local usercodes ($devid)...") if ( $self->{debug} ); &main::print_log("cmd=$cmd") if ( $self->{debug} > 1 ); - my ( $isSuccessResponse0, $status ) = - &raZberry::_get_JSON_data( $self->{master_object}, 'usercode', $cmd ); + my ( $isSuccessResponse0, $status ) = &raZberry::_get_JSON_data( $self->{master_object}, 'usercode', $cmd ); unless ($isSuccessResponse0) { - &main::print_log( - "[raZberry] Error: Problem retrieving data from " . $self->{host} ); + &main::print_log( "[raZberry]: Error: Problem retrieving data from " . $self->{host} ); $self->{data}->{retry}++; return ('0'); } $cmd = "%5B" . $devid . "%5D.UserCode.data"; - &main::print_log("[raZberry] Downloading local usercodes from $devid...") + &main::print_log("[raZberry]: Downloading local usercodes from $devid...") if ( $self->{debug} ); &main::print_log("cmd=$cmd") if ( $self->{debug} > 1 ); - my ( $isSuccessResponse1, $response ) = - &raZberry::_get_JSON_data( $self->{master_object}, 'usercode_data', - $cmd ); + my ( $isSuccessResponse1, $response ) = &raZberry::_get_JSON_data( $self->{master_object}, 'usercode_data', $cmd ); unless ($isSuccessResponse1) { - &main::print_log( - "[raZberry] Error: Problem retrieving data from " . $self->{host} ); + &main::print_log( "[raZberry]: Error: Problem retrieving data from " . $self->{host} ); $self->{data}->{retry}++; return ('0'); } @@ -1197,8 +1249,7 @@ sub _update_users { # print Dumper $response if ( $self->{debug} > 1 ); foreach my $key ( keys %{$response} ) { if ( $key =~ m/^[0-9]*$/ ) { #a number, so a user code - $self->{users}->{"$key"}->{status} = - $response->{"$key"}->{status}->{value}; + $self->{users}->{"$key"}->{status} = $response->{"$key"}->{status}->{value}; } } @@ -1226,7 +1277,7 @@ sub new { sub set { my ( $self, $p_state, $p_setby ) = @_; - if ( $p_setby eq 'poll' ) { + if ( defined $p_setby && ( ( $p_setby eq 'poll' ) or ( $p_setby eq 'push' ) ) ) { $self->SUPER::set($p_state); } } @@ -1245,22 +1296,14 @@ sub new { my $self = {}; bless $self, $class; if ( ( defined $deg ) and ( lc $deg eq "f" ) ) { - push( - @{ $$self{states} }, - 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, - 71, 72, 73, 74, 75, 76, 77, 78, 79, 80 - ); + push( @{ $$self{states} }, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80 ); $self->{units} = "F"; $self->{min_temp} = 58; $self->{max_temp} = 80; } else { - push( - @{ $$self{states} }, - 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, - 22, 23, 24, 25, 16, 27, 28, 29, 30 - ); + push( @{ $$self{states} }, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 16, 27, 28, 29, 30 ); $self->{units} = "C"; $self->{min_temp} = 10; $self->{max_temp} = 30; @@ -1282,7 +1325,7 @@ sub new { sub set { my ( $self, $p_state, $p_setby ) = @_; - if ( $p_setby eq 'poll' ) { + if ( defined $p_setby && ( ( $p_setby eq 'poll' ) or ( $p_setby eq 'push' ) ) ) { $self->{level} = $p_state; $self->SUPER::set($p_state); } @@ -1290,10 +1333,7 @@ sub set { if ( ( $p_state < $self->{min_temp} ) or ( $p_state > $self->{max_temp} ) ) { - main::pring_log( - "[raZberry]: WARNING not setting level to $p_state since out of bounds " - . $self->{min_temp} . ":" - . $self->{max_temp} ); + main::pring_log( "[raZberry]: WARNING not setting level to $p_state since out of bounds " . $self->{min_temp} . ":" . $self->{max_temp} ); } else { $$self{master_object}->set_dev( $$self{devid}, "level=$p_state" ); @@ -1331,19 +1371,11 @@ sub update_data { #if units is F then rescale states if ( $data->{units} =~ m/F/ ) { - @{ $$self{states} } = ( - 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, - 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80 - ); + @{ $$self{states} } = ( 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80 ); } $self->{min_temp} = $data->{temp_min}; $self->{max_temp} = $data->{temp_max}; - main::print_log( "In set, units = " - . $data->{units} - . " max = " - . $data->{temp_max} - . " min = " - . $data->{temp_min} ) + main::print_log( "In set, units = " . $data->{units} . " max = " . $data->{temp_max} . " min = " . $data->{temp_min} ) if ( $self->{debug} ); } @@ -1372,7 +1404,7 @@ sub new { sub set { my ( $self, $p_state, $p_setby ) = @_; - if ( $p_setby eq 'poll' ) { + if ( defined $p_setby && ( ( $p_setby eq 'poll' ) or ( $p_setby eq 'push' ) ) ) { $self->{level} = $p_state; $self->SUPER::set($p_state); @@ -1463,7 +1495,7 @@ sub new { sub set { my ( $self, $p_state, $p_setby ) = @_; - if ( $p_setby eq 'poll' ) { + if ( defined $p_setby && ( ( $p_setby eq 'poll' ) or ( $p_setby eq 'push' ) ) ) { $self->{level} = $p_state; my $n_state; if ( $p_state eq "on" ) { @@ -1472,15 +1504,12 @@ sub set { else { $n_state = "closed"; } - main::print_log( - "[raZberry] Setting openclose value to $n_state. Level is " - . $self->{level} ) + main::print_log( "[raZberry]: Setting openclose value to $n_state. Level is " . $self->{level} ) if ( $self->{debug} ); $self->SUPER::set($n_state); } else { - main::print_log( - "[raZberry] ERROR Can not set state $p_state for openclose"); + main::print_log("[raZberry]: ERROR Can not set state $p_state for openclose"); } } @@ -1542,13 +1571,10 @@ sub update_data { sub battery_check { my ($self) = @_; if ( $self->{battery_level} eq "" ) { - main::print_log( - "[raZberry_battery] INFO Battery level currently undefined"); + main::print_log("[raZberry_battery] INFO Battery level currently undefined"); return; } - main::print_log( "[raZberry_battery] INFO Battery currently at " - . $self->{battery_level} - . "%" ); + main::print_log( "[raZberry_battery] INFO Battery currently at " . $self->{battery_level} . "%" ); if ( ( $self->{battery_level} < 30 ) and ( $self->{battery_alert} == 0 ) ) { $self->{battery_alert} = 1; main::speak("Warning, Zwave battery has less than 30% charge"); @@ -1558,4 +1584,120 @@ sub battery_check { } } -1; +package raZberry_voltage; +@raZberry_voltage::ISA = ('Generic_Item'); + +sub new { + my ( $class, $object, $devid, $options ) = @_; + + my $self = {}; + bless $self, $class; + + #ZWayVDev_zway_x-0-50-0 - Power Meter kWh + #ZWayVDev_zway_x-0-50-1 - RGB setting of the switch LED + #ZWayVDev_zway_x-0-50-2 - Power Sensor W + #ZWayVDev_zway_x-0-50-4 - Voltage Sensor V + #ZWayVDev_zway_x-0-50-5 - Current Sensor A + #push( @{ $$self{states} }, 'on', 'off'); I'm not sure we should set the states here, since it's not a controlable item? + + unless ( $devid =~ m/^\d+$/ ) { + $$self{master_object} = $object; + $$self{type} = "Multilevel Voltage"; + $$self{devid} = $devid; + $object->register( $self, $devid . "-0-50-0", $options ); + $object->register( $self, $devid . "-0-50-1", $options ); + $object->register( $self, $devid . "-0-50-2", $options ); + $object->register( $self, $devid . "-0-50-4", $options ); + $object->register( $self, $devid . "-0-50-5", $options ); + + #$self->set($object->get_dev_status,$devid,'poll'); + $self->{level}->{0} = ""; + $self->{debug} = $object->{debug}; + } + else { + main::print_log("[raZberry_voltage] ERROR, Voltage can only be a major dev id"); + + } + return $self; + +} + +sub level { + my ( $self, $attr ) = @_; + + $attr = 0 unless ($attr); + if ( defined $self->{level}->{$attr} ) { + return ( $self->{level} ); + } + else { + main::print_log("[raZberry_voltage] ERROR, unknown attribute $attr"); + return (0); + } +} + +sub set_level { + my ( $self, $value, $attr ) = @_; + + $attr = 0 unless ($attr); + $self->{level}->{$attr} = $value; + +} + +sub ping { + my ($self) = @_; + + $$self{master_object}->ping_dev( $$self{devid} ); +} + +sub isfailed { + my ($self) = @_; + + $$self{master_object}->isfailed_dev( $$self{devid} ); +} + +sub update_data { + my ( $self, $data ) = @_; +} + +package raZberry_generic; +@raZberry_generic::ISA = ('Generic_Item'); + +sub new { + my ( $class, $object, $devid, $options ) = @_; + + my $self = {}; + bless $self, $class; + + $$self{master_object} = $object; + $$self{type} = "Generic"; + $$self{devid} = $devid; + $object->register( $self, $devid, $options ); + + #$self->set($object->get_dev_status,$devid,'poll'); + $self->{level} = ""; + $self->{debug} = $object->{debug}; + return $self; + +} + +sub level { + my ($self) = @_; + + return ( $self->{level} ); +} + +sub ping { + my ($self) = @_; + + $$self{master_object}->ping_dev( $$self{devid} ); +} + +sub isfailed { + my ($self) = @_; + + $$self{master_object}->isfailed_dev( $$self{devid} ); +} + +sub update_data { + my ( $self, $data ) = @_; +} diff --git a/lib/read_table_A.pl b/lib/read_table_A.pl index 5718ce038..c6177ed33 100644 --- a/lib/read_table_A.pl +++ b/lib/read_table_A.pl @@ -15,8 +15,7 @@ #print_log "Using read_table_A.pl"; -my ( %groups, %objects, %packages, %addresses, %scene_build_controllers, - %scene_build_responders ); +my ( %groups, %objects, %packages, %addresses, %scene_build_controllers, %scene_build_responders ); sub read_table_init_A { @@ -40,10 +39,8 @@ sub read_table_A { $record =~ s/\s*#.*$//; my ( - $code, $address, $name, $object, - $grouplist, $comparison, $limit, @other, - $other, $vcommand, $occupancy, $network, - $password, $interface, $additional_code + $code, $address, $name, $object, $grouplist, $comparison, $limit, @other, + $other, $vcommand, $occupancy, $network, $password, $interface, $additional_code ); my (@item_info) = split( ',\s*', $record ); my $type = uc shift @item_info; @@ -69,58 +66,57 @@ sub read_table_A { require Clipsal_CBus; require Clipsal_CBus::CGate; ( $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Clipsal_CBus::CGate('Clipsal_CBus_Cgate',$other)"; } elsif ( $type eq "CBUS_GROUP" ) { require Clipsal_CBus::Group; ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Clipsal_CBus::Group('$address','$name',$other)"; } elsif ( $type eq "CBUS_TRIGGER" ) { require Clipsal_CBus::TriggerGroup; ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Clipsal_CBus::TriggerGroup('$address','$name',$other)"; } elsif ( $type eq "CBUS_UNIT" ) { require Clipsal_CBus::Unit; ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Clipsal_CBus::Unit('$address','$name',$other)"; } # -[ UPB ]---------------------------------------------------------- elsif ( $type eq "UPBPIM" ) { require 'UPBPIM.pm'; - ( $name, $network, $password, $address, $grouplist, @other ) = - @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + ( $name, $network, $password, $address, $grouplist, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "UPBPIM('UPBPIM', $network,$password,$address)"; } elsif ( $type eq "UPBD" ) { require 'UPB_Device.pm'; ( $name, $object, $network, $address, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "UPB_Device(\$$object, $network,$address)"; } elsif ( $type eq "UPBL" ) { require 'UPB_Link.pm'; ( $name, $object, $network, $address, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "UPB_Link(\$$object, $network,$address)"; } elsif ( $type eq "UPBRAIN8" ) { require 'UPB_Rain8.pm'; ( $name, $object, $network, $address, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "UPB_Rain8(\$$object, $network,$address)"; } elsif ( $type eq "UPBT" ) { require 'UPB_Thermostat.pm'; ( $name, $object, $network, $address, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "UPB_Thermostat(\$$object, $network,$address)"; } @@ -128,237 +124,165 @@ sub read_table_A { elsif ( $type eq "INSTEON_PLM" ) { require Insteon_PLM; ( $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon_PLM('Insteon_PLM',$other)"; } elsif ( $type eq "INSTEON_LAMPLINC" ) { require Insteon::Lighting; - if ( - validate_def( - $type, 2, [ 'insteon_address', 'name' ], \@item_info - ) - ) - { + if ( validate_def( $type, 2, [ 'insteon_address', 'name' ], \@item_info ) ) { ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::LampLinc(\'$address\',$other)"; } } elsif ( $type eq "INSTEON_BULBLINC" ) { require Insteon::Lighting; - if ( - validate_def( - $type, 2, [ 'insteon_address', 'name' ], \@item_info - ) - ) - { + if ( validate_def( $type, 2, [ 'insteon_address', 'name' ], \@item_info ) ) { ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::BulbLinc(\'$address\',$other)"; } } elsif ( $type eq "INSTEON_APPLIANCELINC" ) { require Insteon::Lighting; - if ( - validate_def( - $type, 2, [ 'insteon_address', 'name' ], \@item_info - ) - ) - { + if ( validate_def( $type, 2, [ 'insteon_address', 'name' ], \@item_info ) ) { ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::ApplianceLinc(\'$address\',$other)"; } } elsif ( $type eq "INSTEON_SWITCHLINC" ) { require Insteon::Lighting; - if ( - validate_def( - $type, 2, [ 'insteon_address', 'name' ], \@item_info - ) - ) - { + if ( validate_def( $type, 2, [ 'insteon_address', 'name' ], \@item_info ) ) { ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::SwitchLinc(\'$address\',$other)"; } } elsif ( $type eq "INSTEON_SWITCHLINCRELAY" ) { require Insteon::Lighting; - if ( - validate_def( - $type, 2, [ 'insteon_address', 'name' ], \@item_info - ) - ) - { + if ( validate_def( $type, 2, [ 'insteon_address', 'name' ], \@item_info ) ) { ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::SwitchLincRelay(\'$address\',$other)"; } } elsif ( $type eq "INSTEON_KEYPADLINC" ) { require Insteon::Lighting; - if ( - validate_def( - $type, 2, - [ - qr/^[[:xdigit:]]{2}\.[[:xdigit:]]{2}\.[[:xdigit:]]{2}:[[:xdigit:]]{2}$/, - 'name' - ], - \@item_info - ) - ) - { + if ( validate_def( $type, 2, [ qr/^[[:xdigit:]]{2}\.[[:xdigit:]]{2}\.[[:xdigit:]]{2}:[[:xdigit:]]{2}$/, 'name' ], \@item_info ) ) { ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::KeyPadLinc(\'$address\', $other)"; } } elsif ( $type eq "INSTEON_KEYPADLINCRELAY" ) { require Insteon::Lighting; - if ( - validate_def( - $type, 2, - [ - qr/^[[:xdigit:]]{2}\.[[:xdigit:]]{2}\.[[:xdigit:]]{2}:[[:xdigit:]]{2}$/, - 'name' - ], - \@item_info - ) - ) - { + if ( validate_def( $type, 2, [ qr/^[[:xdigit:]]{2}\.[[:xdigit:]]{2}\.[[:xdigit:]]{2}:[[:xdigit:]]{2}$/, 'name' ], \@item_info ) ) { ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::KeyPadLincRelay(\'$address\', $other)"; } } elsif ( $type eq "INSTEON_REMOTELINC" ) { require Insteon::Controller; ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::RemoteLinc(\'$address\', $other)"; } elsif ( $type eq "INSTEON_MOTIONSENSOR" ) { require Insteon::Security; ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::MotionSensor(\'$address\', $other)"; } elsif ( $type eq "INSTEON_TRIGGERLINC" ) { require Insteon::Security; ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::TriggerLinc(\'$address\', $other)"; } elsif ( $type eq "INSTEON_IOLINC" ) { require Insteon::IOLinc; - if ( - validate_def( - $type, 2, [ 'insteon_address', 'name' ], \@item_info - ) - ) - { + if ( validate_def( $type, 2, [ 'insteon_address', 'name' ], \@item_info ) ) { ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::IOLinc(\'$address\', $other)"; } } - elsif($type eq "INSTEON_EZIO8SA") { + elsif ( $type eq "INSTEON_EZIO8SA" ) { require Insteon::EZIO8SA; - if ( - validate_def( - $type, 2, - [ - qr/^[[:xdigit:]]{2}\.[[:xdigit:]]{2}\.[[:xdigit:]]{2}:[[:xdigit:]]{2}$/, - 'name' - ], - \@item_info - ) - ) - { - ($address, $name, $grouplist, @other) = @item_info; - $other = join ', ', (map {"'$_'"} @other); # Quote data + if ( validate_def( $type, 2, [ qr/^[[:xdigit:]]{2}\.[[:xdigit:]]{2}\.[[:xdigit:]]{2}:[[:xdigit:]]{2}$/, 'name' ], \@item_info ) ) { + ( $address, $name, $grouplist, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::EZIO8SA(\'$address\', $other)"; } } - elsif($type eq "INSTEON_EZIO8SA_RELAY") { + elsif ( $type eq "INSTEON_EZIO8SA_RELAY" ) { require Insteon::EZIO8SA; - ($address, $object, $name, $grouplist, @other) = @item_info; - $other = join ', ', (map {"'$_'"} @other); # Quote data + ( $address, $object, $name, $grouplist, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::EZIO8SA_relay($address, $object, $other)"; } - elsif($type eq "INSTEON_EZIO8SA_INPUT") { + elsif ( $type eq "INSTEON_EZIO8SA_INPUT" ) { require Insteon::Lighting; - if ( - validate_def( - $type, 2, - [ - qr/^[[:xdigit:]]{2}\.[[:xdigit:]]{2}\.[[:xdigit:]]{2}:[[:xdigit:]]{2}$/, - 'name' - ], - \@item_info - ) - ) - { - ($address, $name, $grouplist, @other) = @item_info; - $other = join ', ', (map {"'$_'"} @other); # Quote data + if ( validate_def( $type, 2, [ qr/^[[:xdigit:]]{2}\.[[:xdigit:]]{2}\.[[:xdigit:]]{2}:[[:xdigit:]]{2}$/, 'name' ], \@item_info ) ) { + ( $address, $name, $grouplist, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::SwitchLincRelay(\'$address\',$other)"; } } elsif ( $type eq "INSTEON_FANLINC" ) { require Insteon::Lighting; ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::FanLinc(\'$address\', $other)"; } elsif ( $type eq "INSTEON_ICONTROLLER" ) { require Insteon::BaseInsteon; ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data my ( $deviceid, $groupid ) = $address =~ /(\S+):(\S+)/; if ($groupid) { - $object = - "Insteon::InterfaceController(\'00.00.00:$groupid\', $other)"; + $object = "Insteon::InterfaceController(\'00.00.00:$groupid\', $other)"; } else { - $object = - "Insteon::InterfaceController(\'00.00.00:$address\', $other)"; + $object = "Insteon::InterfaceController(\'00.00.00:$address\', $other)"; } } elsif ( $type eq 'IPLT' or $type eq 'INSTEON_THERMOSTAT' ) { require Insteon::Thermostat; ( $address, $name, $grouplist, $object, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::Thermostat(\'$address\', $other)"; } elsif ( $type eq "INSTEON_IRRIGATION" ) { require Insteon::Irrigation; ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::Irrigation(\'$address\', $other)"; } elsif ( $type eq "INSTEON_SYNCHROLINC" ) { require Insteon::Energy; ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::SynchroLinc(\'$address\', $other)"; } elsif ( $type eq "INSTEON_IMETER" ) { require Insteon::Energy; ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::iMeter(\'$address\', $other)"; } elsif ( $type eq "INSTEON_MICROSWITCH" ) { require Insteon::Lighting; ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::MicroSwitch(\'$address\', $other)"; } elsif ( $type eq "INSTEON_MICROSWITCHRELAY" ) { require Insteon::Lighting; ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "Insteon::MicroSwitchRelay(\'$address\', $other)"; } @@ -366,46 +290,42 @@ sub read_table_A { elsif ( $type eq 'FROG' ) { require 'FroggyRita.pm'; ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "FroggyRita('$address', $other)"; } elsif ( $type eq "X10A" ) { - if ( validate_def( $type, 2, [ 'x10_address', 'name' ], \@item_info ) ) - { + if ( validate_def( $type, 2, [ 'x10_address', 'name' ], \@item_info ) ) { ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "X10_Appliance('$address', $other)"; } } elsif ( $type eq "X10I" ) { - if ( validate_def( $type, 2, [ 'x10_address', 'name' ], \@item_info ) ) - { + if ( validate_def( $type, 2, [ 'x10_address', 'name' ], \@item_info ) ) { ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "X10_Item('$address', $other)"; } } elsif ( $type eq "X10TR" ) { ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "X10_Transmitter('$address', $other)"; } elsif ( $type eq "X10O" ) { ( $address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "X10_Ote('$address', $other)"; } elsif ( $type eq "X10SL" ) { - if ( validate_def( $type, 2, [ 'x10_address', 'name' ], \@item_info ) ) - { + if ( validate_def( $type, 2, [ 'x10_address', 'name' ], \@item_info ) ) { ( $address, $name, $grouplist, @other ) = @item_info; $other = join ', ', ( map { "'$_'" } @other ); $object = "X10_Switchlinc('$address', $other)"; } } elsif ( $type eq "X10AL" ) { - if ( validate_def( $type, 2, [ 'x10_address', 'name' ], \@item_info ) ) - { + if ( validate_def( $type, 2, [ 'x10_address', 'name' ], \@item_info ) ) { ( $address, $name, $grouplist, @other ) = @item_info; $other = join ', ', ( map { "'$_'" } @other ); $object = "X10_Appliancelinc('$address', $other)"; @@ -417,8 +337,7 @@ sub read_table_A { $object = "X10_Keypadlinc('$address', $other)"; } elsif ( $type eq "X10LL" ) { - if ( validate_def( $type, 2, [ 'x10_address', 'name' ], \@item_info ) ) - { + if ( validate_def( $type, 2, [ 'x10_address', 'name' ], \@item_info ) ) { ( $address, $name, $grouplist, @other ) = @item_info; $other = join ', ', ( map { "'$_'" } @other ); $object = "X10_Lamplinc('$address', $other)"; @@ -450,8 +369,7 @@ sub read_table_A { $object = "RCS_Item('$address', $other)"; } elsif ( $type eq "X10MS" ) { - if ( validate_def( $type, 2, [ 'x10_address', 'name' ], \@item_info ) ) - { + if ( validate_def( $type, 2, [ 'x10_address', 'name' ], \@item_info ) ) { ( $address, $name, $grouplist, @other ) = @item_info; $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "X10_Sensor('$address', '$name', $other)"; @@ -464,8 +382,7 @@ sub read_table_A { } elsif ( $type eq "COMPOOL" ) { ( $address, $name, $grouplist ) = @item_info; - ( $address, $comparison, $limit ) = - $address =~ /\s*(\w+)\s*(\<|\>|\=)*\s*(\d*)/; + ( $address, $comparison, $limit ) = $address =~ /\s*(\w+)\s*(\<|\>|\=)*\s*(\d*)/; $object = "Compool_Item('$address', '$comparison', '$limit')" if $comparison ne undef; $object = "Compool_Item('$address')" if $comparison eq undef; @@ -536,18 +453,19 @@ sub read_table_A { ( $name, $grouplist, @other ) = @item_info; $object = "Occupancy_Monitor( $other)"; } - elsif($type eq "DSC") { + elsif ( $type eq "DSC" ) { require 'dsc.pm'; - ($name, $grouplist, @other) = @item_info; + ( $name, $grouplist, @other ) = @item_info; + # $grouplist translates to $type in the new object definition call $object = "DSC('$name', '$grouplist')"; } - elsif($type eq "DSC_PARTITION") { - ($name, $object, $address, $other, $grouplist, @other) = @item_info; + elsif ( $type eq "DSC_PARTITION" ) { + ( $name, $object, $address, $other, $grouplist, @other ) = @item_info; $object = "DSC::Partition(\$$object, '$address')"; } - elsif($type eq "DSC_ZONE") { - ($name, $object, $address, $other, $grouplist, @other) = @item_info; + elsif ( $type eq "DSC_ZONE" ) { + ( $name, $object, $address, $other, $grouplist, @other ) = @item_info; $object = "DSC::Zone(\$$object, '$address', '$other')"; } elsif ( $type eq "MUSICA" ) { @@ -680,12 +598,11 @@ sub read_table_A { if ( !( $vcommand =~ /.*\[.*/ ) ) { $vcommand .= " [ON,OFF]"; } - $code .= sprintf "\nmy \$v_%s_state;\n", $name; - $code .= sprintf "\$v_%s = new Voice_Cmd(\"%s\");\n", $name, $vcommand; - $code .= sprintf "if (\$v_%s_state = said \$v_%s) {\n", $name, $name; - $code .= sprintf " set \$%s \$v_%s_state;\n", $name, $name; - $code .= sprintf " respond \"Turning %s \$v_%s_state\";\n", - $fixedname, $name; + $code .= sprintf "\nmy \$v_%s_state;\n", $name; + $code .= sprintf "\$v_%s = new Voice_Cmd(\"%s\");\n", $name, $vcommand; + $code .= sprintf "if (\$v_%s_state = said \$v_%s) {\n", $name, $name; + $code .= sprintf " set \$%s \$v_%s_state;\n", $name, $name; + $code .= sprintf " respond \"Turning %s \$v_%s_state\";\n", $fixedname, $name; $code .= sprintf "}\n"; return $code; } @@ -729,7 +646,7 @@ sub read_table_A { else { $object = "Sensor_Zone('$address')"; } - if ( !$packages{caddx}++ ) { # first time for this object type? + if ( !$packages{caddx}++ ) { # first time for this object type? $code .= "use caddx;\n"; } } @@ -751,14 +668,11 @@ sub read_table_A { ( $address, $name, $grouplist, $serial, $pa_type, @other ) = @item_info; $pa_type = 'wdio' unless $pa_type; - if ( !$packages{PAobj}++ ) { # first time for this object type? - $code .= - "my (%pa_weeder_max_port,%pa_zone_types,%pa_zone_type_by_zone);\n"; + if ( !$packages{PAobj}++ ) { # first time for this object type? + $code .= "my (%pa_weeder_max_port,%pa_zone_types,%pa_zone_type_by_zone);\n"; } - $code .= - sprintf "\n\$%-35s = new PAobj_zone('%s','%s','%s','%s','%s');\n", - "pa_$name", $address, $name, $grouplist, $serial, $pa_type; + $code .= sprintf "\n\$%-35s = new PAobj_zone('%s','%s','%s','%s','%s');\n", "pa_$name", $address, $name, $grouplist, $serial, $pa_type; $name = "pa_$name"; $grouplist = "|$grouplist|allspeakers"; @@ -772,64 +686,47 @@ sub read_table_A { # AHB / ALB or DBH / DBL $address =~ s/^(\S)(\S)$/$1H$2/; # if $pa_type eq 'wdio'; $address = "D$address" if $pa_type eq 'wdio_old'; - $code .= sprintf "\$%-35s = new Serial_Item('%s','on','%s');\n", - $name . '_obj', $address, $serial; + $code .= sprintf "\$%-35s = new Serial_Item('%s','on','%s');\n", $name . '_obj', $address, $serial; $address =~ s/^(\S{1,2})H(\S)$/$1L$2/; - $code .= sprintf "\$%-35s -> add ('%s','off');\n", $name . '_obj', - $address; + $code .= sprintf "\$%-35s -> add ('%s','off');\n", $name . '_obj', $address; $object = ''; } elsif ( lc $pa_type eq 'object' ) { if ( $name =~ /^pa_pa_/i ) { - print - "\nObject name \"$name\" starts with \"pa_\". This will cause conflicts. Ignoring entry"; + print "\nObject name \"$name\" starts with \"pa_\". This will cause conflicts. Ignoring entry"; } else { - $code .= sprintf "\$%-35s -> tie_items(\$%s,'off','off');\n", - $name, $address; - $code .= sprintf "\$%-35s -> tie_items(\$%s,'on','on');\n", - $name, $address; + $code .= sprintf "\$%-35s -> tie_items(\$%s,'off','off');\n", $name, $address; + $code .= sprintf "\$%-35s -> tie_items(\$%s,'on','on');\n", $name, $address; } } elsif ( lc $pa_type eq 'audrey' ) { require 'Audrey_Play.pm'; - $code .= sprintf "\$%-35s = new Audrey_Play('%s');\n", - $name . '_obj', $address; + $code .= sprintf "\$%-35s = new Audrey_Play('%s');\n", $name . '_obj', $address; $code .= sprintf "\$%-35s -> hidden(1);\n", $name . '_obj'; } elsif ( lc $pa_type eq 'x10' ) { $other = join ', ', ( map { "'$_'" } @other ); # Quote data - $code .= sprintf "\$%-35s = new X10_Appliance('%s','%s');\n", - $name . '_obj', $address, $serial; + $code .= sprintf "\$%-35s = new X10_Appliance('%s','%s');\n", $name . '_obj', $address, $serial; $code .= sprintf "\$%-35s -> hidden(1);\n", $name . '_obj'; - $code .= sprintf "\$%-35s -> tie_items(\$%s,'off','off');\n", - $name, $name . '_obj'; - $code .= sprintf "\$%-35s -> tie_items(\$%s,'on','on');\n", $name, - $name . '_obj'; + $code .= sprintf "\$%-35s -> tie_items(\$%s,'off','off');\n", $name, $name . '_obj'; + $code .= sprintf "\$%-35s -> tie_items(\$%s,'on','on');\n", $name, $name . '_obj'; } elsif ( lc $pa_type eq 'xap' ) { - $code .= sprintf "\$%-35s = new xAP_Item('%s');\n", $name . '_obj', - $address; - $code .= sprintf "\$%-35s -> hidden(1);\n", $name . '_obj'; - $code .= sprintf "\$%-35s -> target_address('%s');\n", - $name . '_obj', $address; - $code .= sprintf "\$%-35s -> class_name('%s');\n", $name . '_obj', - $serial; - $code .= sprintf "\$%-35s -> tie_items(\$%s,'on','on');\n", $name, - $name . '_obj'; + $code .= sprintf "\$%-35s = new xAP_Item('%s');\n", $name . '_obj', $address; + $code .= sprintf "\$%-35s -> hidden(1);\n", $name . '_obj'; + $code .= sprintf "\$%-35s -> target_address('%s');\n", $name . '_obj', $address; + $code .= sprintf "\$%-35s -> class_name('%s');\n", $name . '_obj', $serial; + $code .= sprintf "\$%-35s -> tie_items(\$%s,'on','on');\n", $name, $name . '_obj'; } elsif ( lc $pa_type eq 'xpl' ) { - $code .= sprintf "\$%-35s = new xPL_Item('%s');\n", $name . '_obj', - $address; - $code .= sprintf "\$%-35s -> hidden(1);\n", $name . '_obj'; - $code .= sprintf "\$%-35s -> target_address('%s');\n", - $name . '_obj', $address; - $code .= sprintf "\$%-35s -> class_name('%s');\n", $name . '_obj', - $serial; - $code .= sprintf "\$%-35s -> tie_items(\$%s,'on','on');\n", $name, - $name . '_obj'; + $code .= sprintf "\$%-35s = new xPL_Item('%s');\n", $name . '_obj', $address; + $code .= sprintf "\$%-35s -> hidden(1);\n", $name . '_obj'; + $code .= sprintf "\$%-35s -> target_address('%s');\n", $name . '_obj', $address; + $code .= sprintf "\$%-35s -> class_name('%s');\n", $name . '_obj', $serial; + $code .= sprintf "\$%-35s -> tie_items(\$%s,'on','on');\n", $name, $name . '_obj'; } elsif ( lc $pa_type eq 'aviosys' ) { my $aviosysref = { @@ -854,10 +751,8 @@ sub read_table_A { '8' => ']' } }; - $code .= sprintf "\$%-35s = new Serial_Item('%s','on','%s');\n", - $name . '_obj', $aviosysref->{'on'}{$address}, $serial; - $code .= sprintf "\$%-35s -> add ('%s','off');\n", $name . '_obj', - $aviosysref->{'off'}{$address}; + $code .= sprintf "\$%-35s = new Serial_Item('%s','on','%s');\n", $name . '_obj', $aviosysref->{'on'}{$address}, $serial; + $code .= sprintf "\$%-35s -> add ('%s','off');\n", $name . '_obj', $aviosysref->{'off'}{$address}; } elsif ( lc $pa_type eq 'amixer' ) { @@ -878,11 +773,10 @@ sub read_table_A { my $monitor_name; ( $address, $name, $monitor_name, $grouplist, @other ) = @item_info; $other = join ', ', ( map { "'$_'" } @other ); # Quote data - if ( !$packages{ZoneMinder_xAP}++ ) { # first time for this object type? + if ( !$packages{ZoneMinder_xAP}++ ) { # first time for this object type? $code .= "use ZoneMinder_xAP;\n"; } - $code .= sprintf "\n\$%-35s = new ZM_ZoneItem('%s');\n", $name, - $address; + $code .= sprintf "\n\$%-35s = new ZM_ZoneItem('%s');\n", $name, $address; if ( $objects{$monitor_name} ) { $code .= sprintf "\$%-35s -> add(\$%s);\n", $monitor_name, $name; } @@ -897,17 +791,16 @@ sub read_table_A { else { $object = "ZM_MonitorItem('$address')"; } - if ( !$packages{ZoneMinder_xAP}++ ) { # first time for this object type? + if ( !$packages{ZoneMinder_xAP}++ ) { # first time for this object type? $code .= "use ZoneMinder_xAP;\n"; } } elsif ( $type eq "ANALOG_SENSOR" ) { - my $xc_name; #xap conduit + my $xc_name; #xap conduit my $sensor_type; #ANALOG_SENSOR, xap source, object name, xap conduit name, groups, xap sensor type, tokens... - if ( !$packages{AnalogSensor_Item}++ ) - { # first time for this object type? + if ( !$packages{AnalogSensor_Item}++ ) { # first time for this object type? $code .= "use AnalogSensor_Item;\n"; } $address = shift @item_info; @@ -917,19 +810,16 @@ sub read_table_A { $xc_name = $address; ( $name, $grouplist, @other ) = @item_info; $other = join ', ', ( map { "'$_'" } @other ); # Quote data - $code .= sprintf "\n\$%-35s = new AnalogSensor_Item(\$%s, %s);\n", - $name, $xc_name, $other; + $code .= sprintf "\n\$%-35s = new AnalogSensor_Item(\$%s, %s);\n", $name, $xc_name, $other; } else { ( $name, $xc_name, $grouplist, $sensor_type, @other ) = @item_info; $other = join ', ', ( map { "'$_'" } @other ); # Quote data if ( lc $name eq 'auto' ) { #new $name = $xc_name . "_" . $sensor_type . "_" . $address; - $name =~ s/\./_/g; #strip out all the periods from xap names + $name =~ s/\./_/g; #strip out all the periods from xap names } - $code .= - sprintf "\n\$%-35s = new AnalogSensor_Item('%s', '%s', %s);\n", - $name, $address, $sensor_type, $other; + $code .= sprintf "\n\$%-35s = new AnalogSensor_Item('%s', '%s', %s);\n", $name, $address, $sensor_type, $other; if ( $objects{$xc_name} ) { $code .= sprintf "\$%-35s -> add(\$%s);\n", $xc_name, $name; } @@ -937,12 +827,11 @@ sub read_table_A { $object = ''; } elsif ( $type eq "ANALOG_SENSOR_R" ) { - my $xc_name; #xap conduit + my $xc_name; #xap conduit my $sensor_type; #ANALOG_SENSOR_R, xap source, object name, xap conduit name, groups, xap sensor type, tokens... - if ( !$packages{AnalogSensor_Item}++ ) - { # first time for this object type? + if ( !$packages{AnalogSensor_Item}++ ) { # first time for this object type? $code .= "use AnalogSensor_Item;\n"; } $address = shift @item_info; @@ -952,21 +841,16 @@ sub read_table_A { $xc_name = $address; ( $name, $grouplist, @other ) = @item_info; $other = join ', ', ( map { "'$_'" } @other ); # Quote data - $code .= - sprintf "\n\$%-35s = new AnalogRangeSensor_Item(\$%s, %s);\n", - $name, $xc_name, $other; + $code .= sprintf "\n\$%-35s = new AnalogRangeSensor_Item(\$%s, %s);\n", $name, $xc_name, $other; } else { ( $name, $xc_name, $grouplist, $sensor_type, @other ) = @item_info; $other = join ', ', ( map { "'$_'" } @other ); # Quote data if ( lc $name eq 'auto' ) { #new $name = $xc_name . "_" . $sensor_type . "_" . $address; - $name =~ s/\./_/g; #strip out all the periods from xap names + $name =~ s/\./_/g; #strip out all the periods from xap names } - $code .= - sprintf - "\n\$%-35s = new AnalogRangeSensor_Item('%s', '%s', %s);\n", - $name, $address, $sensor_type, $other; + $code .= sprintf "\n\$%-35s = new AnalogRangeSensor_Item('%s', '%s', %s);\n", $name, $address, $sensor_type, $other; if ( $objects{$xc_name} ) { $code .= sprintf "\$%-35s -> add(\$%s);\n", $xc_name, $name; } @@ -979,8 +863,7 @@ sub read_table_A { #ANALOG_SENSOR, xap source, object name, xap conduit name, groups, xap sensor type, tokens... ( $sensor_name, $name, $grouplist, @other ) = @item_info; $other = join ', ', ( map { "'$_'" } @other ); # Quote data - if ( !$packages{AnalogSensor_Item}++ ) - { # first time for this object type? + if ( !$packages{AnalogSensor_Item}++ ) { # first time for this object type? $code .= "use AnalogSensor_Item;\n"; } @@ -1003,7 +886,7 @@ sub read_table_A { else { $object = "OneWire_xAP('$address')"; } - if ( !$packages{OneWire_xAP}++ ) { # first time for this object type? + if ( !$packages{OneWire_xAP}++ ) { # first time for this object type? $code .= "use OneWire_xAP;\n"; } } @@ -1013,7 +896,7 @@ sub read_table_A { #SDX, xap instance, object name, psixc server name ( $address, $name, $server, $grouplist, @other ) = @item_info; $other = join ', ', ( map { "'$_'" } @other ); # Quote data - if ( !$packages{SysDiag_xAP}++ ) { # first time for this object type? + if ( !$packages{SysDiag_xAP}++ ) { # first time for this object type? $code .= "use SysDiag_xAP;\n"; } if ($other) { @@ -1032,7 +915,7 @@ sub read_table_A { else { $object = "BSC_Item('$address')"; } - if ( !$packages{BSC}++ ) { # first time for this object type? + if ( !$packages{BSC}++ ) { # first time for this object type? $code .= "use BSC;\n"; } } @@ -1045,7 +928,7 @@ sub read_table_A { else { $object = "xPL_Sensor('$address')"; } - if ( !$packages{xPL_Items}++ ) { # first time for this object type? + if ( !$packages{xPL_Items}++ ) { # first time for this object type? $code .= "use xPL_Items;\n"; } } @@ -1058,7 +941,7 @@ sub read_table_A { else { $object = "xPL_UPS('$address')"; } - if ( !$packages{xPL_Items}++ ) { # first time for this object type? + if ( !$packages{xPL_Items}++ ) { # first time for this object type? $code .= "use xPL_Items;\n"; } } @@ -1071,7 +954,7 @@ sub read_table_A { else { $object = "xPL_X10Security('$address')"; } - if ( !$packages{xPL_Items}++ ) { # first time for this object type? + if ( !$packages{xPL_Items}++ ) { # first time for this object type? $code .= "use xPL_Items;\n"; } } @@ -1084,7 +967,7 @@ sub read_table_A { else { $object = "xPL_X10Basic('$address')"; } - if ( !$packages{xPL_X10Basic}++ ) { # first time for this objecttype? + if ( !$packages{xPL_X10Basic}++ ) { # first time for this objecttype? $code .= "use xPL_X10Basic;\n"; } } @@ -1097,7 +980,7 @@ sub read_table_A { else { $object = "xPL_IrrigationGateway('$address')"; } - if ( !$packages{xPL_Irrigation}++ ) { # first time for this object type? + if ( !$packages{xPL_Irrigation}++ ) { # first time for this object type? $code .= "use xPL_Irrigation;\n"; } } @@ -1110,7 +993,7 @@ sub read_table_A { else { $object = "xPL_IrrigationValve('$address',\$$object)"; } - if ( !$packages{xPL_Irrigation}++ ) { # first time for this object type? + if ( !$packages{xPL_Irrigation}++ ) { # first time for this object type? $code .= "use xPL_Irrigation;\n"; } } @@ -1123,7 +1006,7 @@ sub read_table_A { else { $object = "xPL_IrrigationQueue('$address',\$$object)"; } - if ( !$packages{xPL_Irrigation}++ ) { # first time for this object type? + if ( !$packages{xPL_Irrigation}++ ) { # first time for this object type? $code .= "use xPL_Irrigation;\n"; } } @@ -1136,7 +1019,7 @@ sub read_table_A { else { $object = "xPL_LightGateway('$address')"; } - if ( !$packages{xPL_Lighting}++ ) { # first time for this object type? + if ( !$packages{xPL_Lighting}++ ) { # first time for this object type? $code .= "use xPL_Lighting;\n"; } } @@ -1149,7 +1032,7 @@ sub read_table_A { else { $object = "xPL_Light('$address',\$$object)"; } - if ( !$packages{xPL_Lighting}++ ) { # first time for this object type? + if ( !$packages{xPL_Lighting}++ ) { # first time for this object type? $code .= "use xPL_Lighting;\n"; } } @@ -1162,7 +1045,7 @@ sub read_table_A { else { $object = "xPL_PlugwiseGateway('$address')"; } - if ( !$packages{xPL_Plugwise}++ ) { # first time for this object type? + if ( !$packages{xPL_Plugwise}++ ) { # first time for this object type? $code .= "use xPL_Plugwise;\n"; } } @@ -1175,7 +1058,7 @@ sub read_table_A { else { $object = "xPL_Plugwise('$address',\$$object)"; } - if ( !$packages{xPL_Plugwise}++ ) { # first time for this object type? + if ( !$packages{xPL_Plugwise}++ ) { # first time for this object type? $code .= "use xPL_Plugwise;\n"; } } @@ -1188,7 +1071,7 @@ sub read_table_A { else { $object = "xPL_Squeezebox('$address')"; } - if ( !$packages{xPL_Squeezebox}++ ) { # first time for this object type? + if ( !$packages{xPL_Squeezebox}++ ) { # first time for this object type? $code .= "use xPL_Squeezebox;\n"; } } @@ -1201,7 +1084,7 @@ sub read_table_A { else { $object = "xPL_SecurityGateway('$address')"; } - if ( !$packages{xPL_Security}++ ) { # first time for this object type? + if ( !$packages{xPL_Security}++ ) { # first time for this object type? $code .= "use xPL_Security;\n"; } } @@ -1214,7 +1097,7 @@ sub read_table_A { else { $object = "xPL_Zone('$address',\$$object)"; } - if ( !$packages{xPL_Security}++ ) { # first time for this object type? + if ( !$packages{xPL_Security}++ ) { # first time for this object type? $code .= "use xPL_Security;\n"; } } @@ -1227,7 +1110,7 @@ sub read_table_A { else { $object = "xPL_Area('$address',\$$object)"; } - if ( !$packages{xPL_Security}++ ) { # first time for this object type? + if ( !$packages{xPL_Security}++ ) { # first time for this object type? $code .= "use xPL_Security;\n"; } } @@ -1240,7 +1123,7 @@ sub read_table_A { else { $object = "X10SL_Scene('$address')"; } - if ( !$packages{X10_Scene}++ ) { # first time for this object type? + if ( !$packages{X10_Scene}++ ) { # first time for this object type? $code .= "use X10_Scene;\n"; } } @@ -1253,7 +1136,7 @@ sub read_table_A { else { $object = "Scene()"; } - if ( !$packages{Scene}++ ) { # first time for this object type? + if ( !$packages{Scene}++ ) { # first time for this object type? $code .= "use Scene;\n"; } } @@ -1261,18 +1144,16 @@ sub read_table_A { my ( $scene_name, $on_level, $ramp_rate ); ( $name, $scene_name, $on_level, $ramp_rate ) = @item_info; $other = join ', ', ( map { "'$_'" } @other ); # Quote data - if ( !$packages{X10_Scene}++ ) { # first time for this object type? + if ( !$packages{X10_Scene}++ ) { # first time for this object type? $code .= "use X10_Scene;\n"; } if ( ( $objects{$scene_name} ) and ( $objects{$name} ) ) { if ($on_level) { if ($ramp_rate) { - $code .= sprintf "\$%-35s -> add(\$%s,'%s','%s');\n", - $scene_name, $name, $on_level, $ramp_rate; + $code .= sprintf "\$%-35s -> add(\$%s,'%s','%s');\n", $scene_name, $name, $on_level, $ramp_rate; } else { - $code .= sprintf "\$%-35s -> add(\$%s,'%s');\n", - $scene_name, $name, $on_level; + $code .= sprintf "\$%-35s -> add(\$%s,'%s');\n", $scene_name, $name, $on_level; } } else { @@ -1283,42 +1164,30 @@ sub read_table_A { } elsif ( $type eq "SCENE_MEMBER" ) { my ( $scene_name, $on_level, $ramp_rate ); - if ( - validate_def( - $type, 2, - [ 'name', 'name', 'insteon_on_level', 'insteon_ramp_rate' ], - \@item_info - ) - ) - { + if ( validate_def( $type, 2, [ 'name', 'name', 'insteon_on_level', 'insteon_ramp_rate' ], \@item_info ) ) { ( $name, $scene_name, $on_level, $ramp_rate ) = @item_info; $other = join ', ', ( map { "'$_'" } @other ); # Quote data - if ( !$packages{Scene}++ ) { # first time for this object type? + if ( !$packages{Scene}++ ) { # first time for this object type? $code .= "use Scene;\n"; } if ( ( $objects{$scene_name} ) and ( $objects{$name} ) ) { if ($on_level) { if ($ramp_rate) { - $code .= sprintf "\$%-35s -> add(\$%s,'%s','%s');\n", - $scene_name, $name, $on_level, $ramp_rate; + $code .= sprintf "\$%-35s -> add(\$%s,'%s','%s');\n", $scene_name, $name, $on_level, $ramp_rate; } else { - $code .= sprintf "\$%-35s -> add(\$%s,'%s');\n", - $scene_name, $name, $on_level; + $code .= sprintf "\$%-35s -> add(\$%s,'%s');\n", $scene_name, $name, $on_level; } } else { - $code .= sprintf "\$%-35s -> add(\$%s);\n", $scene_name, - $name; + $code .= sprintf "\$%-35s -> add(\$%s);\n", $scene_name, $name; } } else { - print - "\nThere is no object called $scene_name defined. Ignoring SCENE_MEMBER entry.\n" + print "\nThere is no object called $scene_name defined. Ignoring SCENE_MEMBER entry.\n" unless $objects{$scene_name}; - print - "\nThere is no object called $name defined. Ignoring SCENE_MEMBER entry.\n" + print "\nThere is no object called $name defined. Ignoring SCENE_MEMBER entry.\n" unless $objects{$name}; } $object = ''; @@ -1327,25 +1196,10 @@ sub read_table_A { elsif ( $type eq "SCENE_BUILD" ) { #SCENE_BUILD, scene_name, scene_member, is_controller?, is_responder?, onlevel, ramprate - my ( $scene_member, $is_scene_controller, $is_scene_responder, - $on_level, $ramp_rate ); - if ( - validate_def( - $type, 2, - [ - 'name', 'name', - 'boolean', 'boolean', - 'insteon_on_level', 'insteon_ramp_rate' - ], - \@item_info - ) - ) - { + my ( $scene_member, $is_scene_controller, $is_scene_responder, $on_level, $ramp_rate ); + if ( validate_def( $type, 2, [ 'name', 'name', 'boolean', 'boolean', 'insteon_on_level', 'insteon_ramp_rate' ], \@item_info ) ) { - ( - $name, $scene_member, $is_scene_controller, - $is_scene_responder, $on_level, $ramp_rate - ) = @item_info; + ( $name, $scene_member, $is_scene_controller, $is_scene_responder, $on_level, $ramp_rate ) = @item_info; if ( !$packages{Scene}++ ) { # first time for this object type? $code .= "use Scene;\n"; @@ -1354,8 +1208,7 @@ sub read_table_A { $scene_build_controllers{$name}{$scene_member} = "1"; } if ($is_scene_responder) { - $scene_build_responders{$name}{$scene_member} = - "$on_level,$ramp_rate"; + $scene_build_responders{$name}{$scene_member} = "$on_level,$ramp_rate"; } $object = ''; } @@ -1369,7 +1222,7 @@ sub read_table_A { else { $object = "Philips_Hue('$address')"; } - if ( !$packages{Philips_Hue}++ ) { # first time for this object type? + if ( !$packages{Philips_Hue}++ ) { # first time for this object type? $code .= "use Philips_Hue;\n"; } } @@ -1382,116 +1235,145 @@ sub read_table_A { else { $object = "Philips_Lux('$address')"; } - if ( !$packages{Philips_Hue}++ ) { # first time for this object type? + if ( !$packages{Philips_Hue}++ ) { # first time for this object type? $code .= "use Philips_Hue;\n"; } } + #-------------- RaZberry Objects ----------------- elsif ( $type eq "RAZBERRY_CONTROLLER" ) { - ($address, $name, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + my $poll; + ( $address, $name, $grouplist, $poll, @other ) = @item_info; + $other = join ',', ( map { "$_" } @other ); # Quote data if ($other) { - $object = "raZberry('$address','$other')"; + $object = "raZberry('$address','$poll',$other)"; + } + elsif ($poll) { + $object = "raZberry('$address','$poll')"; } else { - $object = "raZberry('$address')"; - } + $object = "raZberry('$address')"; + } $code .= "use raZberry;\n"; - } + } elsif ( $type eq "RAZBERRY_COMM" ) { - my ($controller); - ($name, $controller, $grouplist ) = @item_info; - $object = "raZberry_comm(\$" . $controller . ")"; + my ($controller); + ( $name, $controller, $grouplist ) = @item_info; + $object = "raZberry_comm(\$" . $controller . ")"; - } + } elsif ( $type eq "RAZBERRY_DIMMER" ) { - my ($devid, $controller); - ($devid, $name, $grouplist, $controller, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + my ( $devid, $controller ); + ( $devid, $name, $grouplist, $controller, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data if ($other) { - $object = "raZberry_dimmer(\$" . $controller . ",'$devid','$other')"; + $object = "raZberry_dimmer(\$" . $controller . ",'$devid','$other')"; } else { - $object = "raZberry_dimmer(\$" . $controller . ",'$devid')"; - } - } + $object = "raZberry_dimmer(\$" . $controller . ",'$devid')"; + } + } elsif ( $type eq "RAZBERRY_SWITCH" ) { - my ($devid, $controller); - ($devid, $name, $grouplist, $controller, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + my ( $devid, $controller ); + ( $devid, $name, $grouplist, $controller, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data if ($other) { - $object = "raZberry_switch(\$" . $controller . ",'$devid','$other')"; + $object = "raZberry_switch(\$" . $controller . ",'$devid','$other')"; } else { - $object = "raZberry_switch(\$" . $controller . ",'$devid')"; - } - } + $object = "raZberry_switch(\$" . $controller . ",'$devid')"; + } + } elsif ( $type eq "RAZBERRY_BLIND" ) { - my ($devid, $controller); - ($devid, $name, $grouplist, $controller, $other ) = @item_info; - #$other = join ', ', ( map { "'$_'" } @other ); # Quote data + my ( $devid, $controller ); + ( $devid, $name, $grouplist, $controller, $other ) = @item_info; + + #$other = join ', ', ( map { "'$_'" } @other ); # Quote data if ($other) { - $object = "raZberry_blind(\$" . $controller . ",'$devid','$other')"; + $object = "raZberry_blind(\$" . $controller . ",'$devid','$other')"; } else { - $object = "raZberry_blind(\$" . $controller . ",'$devid')"; - } - } + $object = "raZberry_blind(\$" . $controller . ",'$devid')"; + } + } elsif ( $type eq "RAZBERRY_LOCK" ) { - my ($devid, $controller); - ($devid, $name, $grouplist, $controller, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + my ( $devid, $controller ); + ( $devid, $name, $grouplist, $controller, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data if ($other) { - $object = "raZberry_lock(\$" . $controller . ",'$devid','$other')"; + $object = "raZberry_lock(\$" . $controller . ",'$devid','$other')"; } else { - $object = "raZberry_lock(\$" . $controller . ",'$devid')"; - } - } + $object = "raZberry_lock(\$" . $controller . ",'$devid')"; + } + } elsif ( $type eq "RAZBERRY_THERMOSTAT" ) { - my ($devid, $controller); - ($devid, $name, $grouplist, $controller, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + my ( $devid, $controller ); + ( $devid, $name, $grouplist, $controller, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data if ($other) { - $object = "raZberry_thermostat(\$" . $controller . ",'$devid','$other')"; + $object = "raZberry_thermostat(\$" . $controller . ",'$devid','$other')"; } else { - $object = "raZberry_thermostat(\$" . $controller . ",'$devid')"; - } - } + $object = "raZberry_thermostat(\$" . $controller . ",'$devid')"; + } + } elsif ( $type eq "RAZBERRY_TEMP_SENSOR" ) { - my ($devid, $controller); - ($devid, $name, $grouplist, $controller, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + my ( $devid, $controller ); + ( $devid, $name, $grouplist, $controller, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data if ($other) { - $object = "raZberry_temp_sensor(\$" . $controller . ",'$devid','$other')"; + $object = "raZberry_temp_sensor(\$" . $controller . ",'$devid','$other')"; } else { - $object = "raZberry_temp_sensor(\$" . $controller . ",'$devid')"; - } - } + $object = "raZberry_temp_sensor(\$" . $controller . ",'$devid')"; + } + } elsif ( $type eq "RAZBERRY_BINARY_SENSOR" ) { - my ($devid, $controller); - ($devid, $name, $grouplist, $controller, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + my ( $devid, $controller ); + ( $devid, $name, $grouplist, $controller, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data + if ($other) { + $object = "raZberry_binary_sensor(\$" . $controller . ",'$devid','$other')"; + } + else { + $object = "raZberry_binary_sensor(\$" . $controller . ",'$devid')"; + } + } + elsif ( $type eq "RAZBERRY_BATTERY" ) { + my ( $devid, $controller ); + ( $devid, $name, $grouplist, $controller, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data + if ($other) { + $object = "raZberry_battery(\$" . $controller . ",'$devid','$other')"; + } + else { + $object = "raZberry_battery(\$" . $controller . ",'$devid')"; + } + } + elsif ( $type eq "RAZBERRY_GENERIC" ) { + my ( $devid, $controller ); + ( $devid, $name, $grouplist, $controller, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data + if ($other) { + $object = "raZberry_generic(\$" . $controller . ",'$devid','$other')"; + } + else { + $object = "raZberry_generic(\$" . $controller . ",'$devid')"; + } + } + elsif ( $type eq "RAZBERRY_VOLTAGE" ) { + my ( $devid, $controller ); + ( $devid, $name, $grouplist, $controller, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data if ($other) { - $object = "raZberry_binary_sensor(\$" . $controller . ",'$devid','$other')"; + $object = "raZberry_voltage(\$" . $controller . ",'$devid','$other')"; } else { - $object = "raZberry_binary_sensor(\$" . $controller . ",'$devid')"; - } - } - elsif ( $type eq "RAZBERRY_BATTERY" ) { - my ($devid, $controller); - ($devid, $name, $grouplist, $controller, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data - if ($other) { - $object = "raZberry_battery(\$" . $controller . ",'$devid','$other')"; - } - else { - $object = "raZberry_battery(\$" . $controller . ",'$devid')"; - } - } + $object = "raZberry_voltage(\$" . $controller . ",'$devid')"; + } + } + #-------------- End of RaZberry Objects ----------------- # -[ MySensors ]------------------------------------------------------ @@ -1499,119 +1381,112 @@ sub read_table_A { require 'MySensors.pm'; my ( $gw_type, $long_name, $port ); ( $name, $long_name, $gw_type, $port, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "MySensors::Interface('$gw_type', '$port', '$long_name', $other)"; } elsif ( $type eq "MYS_NODE" ) { require 'MySensors.pm'; my ( $parent, $long_name ); ( $address, $name, $long_name, $parent, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "MySensors::Node($address, '$long_name', $parent, $other)"; } elsif ( $type eq "MYS_BINARY" ) { require 'MySensors.pm'; my ( $parent, $long_name ); ( $address, $name, $long_name, $parent, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "MySensors::Binary($address, '$long_name', $parent, $other)"; } elsif ( $type eq "MYS_DOOR" ) { require 'MySensors.pm'; my ( $parent, $long_name ); ( $address, $name, $long_name, $parent, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "MySensors::Door($address, '$long_name', $parent, $other)"; } elsif ( $type eq "MYS_MOTION" ) { require 'MySensors.pm'; my ( $parent, $long_name ); ( $address, $name, $long_name, $parent, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "MySensors::Motion($address, '$long_name', $parent, $other)"; } elsif ( $type eq "MYS_TEMPERATURE" ) { require 'MySensors.pm'; my ( $parent, $long_name ); ( $address, $name, $long_name, $parent, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "MySensors::Temperature($address, '$long_name', $parent, $other)"; } elsif ( $type eq "MYS_HUMIDITY" ) { require 'MySensors.pm'; my ( $parent, $long_name ); ( $address, $name, $long_name, $parent, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data - $object = "MySensors::Humidity($address, '$long_name', $parent, $other)"; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $object = "MySensors::Humidity($address, '$long_name', $parent, $other)"; } elsif ( $type eq "MYS_MULTIMETER" ) { require 'MySensors.pm'; my ( $parent, $long_name ); ( $address, $name, $long_name, $parent, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "MySensors::Multimeter($address, '$long_name', $parent, $other)"; } - + #-------------- AD2 Objects ----------------- elsif ( $type eq "AD2_INTERFACE" ) { require AD2; my ($instance); ( $name, $instance, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "AD2('$instance','$other')"; } elsif ( $type eq "AD2_DOOR_ITEM" ) { require AD2; my ( $instance, $expander, $relay, $wireless, $zone, $partition ); - ( $name, $instance, $zone, $partition, $address, $grouplist, @other ) = - @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + ( $name, $instance, $zone, $partition, $address, $grouplist, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data my ( $map, $address ) = split( '=', $address ); $expander = $address if ( uc($map) eq "EXP" ); $relay = $address if ( uc($map) eq "REL" ); $wireless = $address if ( uc($map) eq "RFX" ); - $object = - "AD2_Item('door','$instance','$zone','$partition','$expander','$relay','$wireless','$other')"; + $object = "AD2_Item('door','$instance','$zone','$partition','$expander','$relay','$wireless','$other')"; } elsif ( $type eq "AD2_MOTION_ITEM" ) { require AD2; my ( $instance, $expander, $relay, $wireless, $zone, $partition ); - ( $name, $instance, $zone, $partition, $address, $grouplist, @other ) = - @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + ( $name, $instance, $zone, $partition, $address, $grouplist, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data my ( $map, $address ) = split( '=', $address ); $expander = $address if ( uc($map) eq "EXP" ); $relay = $address if ( uc($map) eq "REL" ); $wireless = $address if ( uc($map) eq "RFX" ); - $object = - "AD2_Item('motion','$instance','$zone','$partition','$expander','$relay','$wireless','$other')"; + $object = "AD2_Item('motion','$instance','$zone','$partition','$expander','$relay','$wireless','$other')"; } elsif ( $type eq "AD2_GENERIC_ITEM" ) { require AD2; my ( $instance, $expander, $relay, $wireless, $zone, $partition ); - ( $name, $instance, $zone, $partition, $address, $grouplist, @other ) = - @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + ( $name, $instance, $zone, $partition, $address, $grouplist, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data my ( $map, $address ) = split( '=', $address ); $expander = $address if ( uc($map) eq "EXP" ); $relay = $address if ( uc($map) eq "REL" ); $wireless = $address if ( uc($map) eq "RFX" ); - $object = - "AD2_Item('','$instance','$zone','$partition','$expander','$relay','$wireless','$other')"; + $object = "AD2_Item('','$instance','$zone','$partition','$expander','$relay','$wireless','$other')"; } elsif ( $type eq "AD2_PARTITION" ) { require AD2; my ( $instance, $number ); - ( $name, $instance, $number, $address, $grouplist, @other ) = - @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + ( $name, $instance, $number, $address, $grouplist, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "AD2_Partition('$instance','$number','$address','$other')"; } elsif ( $type eq "AD2_OUTPUT" ) { require AD2; my ( $instance, $output ); ( $name, $instance, $output, $grouplist, @other ) = @item_info; - $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $other = join ', ', ( map { "'$_'" } @other ); # Quote data $object = "AD2_Output('$instance','$output','$other')"; } @@ -1647,18 +1522,17 @@ sub read_table_A { elsif ( $type =~ /PLCBUS_.*/ ) { require PLCBUS; ( $address, $name, $grouplist, @other ) = @item_info; - ( $object, $grouplist, $additional_code ) = - PLCBUS->generate_code( $type, @item_info ); - } - elsif ($type eq "WINK"){ - ($address, $name, $grouplist, @other) = @item_info; - $other = join ', ', (map {"'$_'"} @other); # Quote data - $object = "Wink('$address',$other)"; - if( ! $packages{Wink}++ ) { # first time for this object type? - $code .= "use Wink;\n"; - &::MainLoop_pre_add_hook( \&Wink::GetDevicesAndStatus, 1 ); - } - } + ( $object, $grouplist, $additional_code ) = PLCBUS->generate_code( $type, @item_info ); + } + elsif ( $type eq "WINK" ) { + ( $address, $name, $grouplist, @other ) = @item_info; + $other = join ', ', ( map { "'$_'" } @other ); # Quote data + $object = "Wink('$address',$other)"; + if ( !$packages{Wink}++ ) { # first time for this object type? + $code .= "use Wink;\n"; + &::MainLoop_pre_add_hook( \&Wink::GetDevicesAndStatus, 1 ); + } + } else { print "\nUnrecognized .mht entry: $record\n"; return; @@ -1681,8 +1555,7 @@ sub read_table_A { } if ( $name eq $group ) { - &::print_log( - "mht object and group name are the same: $name Bad idea!"); + &::print_log("mht object and group name are the same: $name Bad idea!"); } else { # Allow for floorplan data: Bedroom(5,15)|Lights @@ -1725,15 +1598,11 @@ sub read_table_finish_A { #Loop through the controller hash if ( exists $scene_build_controllers{$scene} ) { - foreach my $scene_controller ( - keys %{ $scene_build_controllers{$scene} } ) - { + foreach my $scene_controller ( keys %{ $scene_build_controllers{$scene} } ) { if ( $objects{$scene_controller} ) { #Make a link to each responder in the responder hash - while ( my ( $scene_responder, $responder_data ) = - each( %{ $scene_build_responders{$scene} } ) ) - { + while ( my ( $scene_responder, $responder_data ) = each( %{ $scene_build_responders{$scene} } ) ) { my ( $on_level, $ramp_rate ) = split( ',', $responder_data ); @@ -1742,11 +1611,7 @@ sub read_table_finish_A { { if ($on_level) { if ($ramp_rate) { - $code .= - sprintf - "\$%-35s -> add(\$%s,'%s','%s');\n", - $scene_controller, $scene_responder, - $on_level, $ramp_rate; + $code .= sprintf "\$%-35s -> add(\$%s,'%s','%s');\n", $scene_controller, $scene_responder, $on_level, $ramp_rate; } else { $code .= @@ -1756,23 +1621,19 @@ sub read_table_finish_A { } } else { - $code .= sprintf "\$%-35s -> add(\$%s);\n", - $scene_controller, $scene_responder; + $code .= sprintf "\$%-35s -> add(\$%s);\n", $scene_controller, $scene_responder; } } } } else { - ::print_log( "[Read_Table_A] ERROR: There is no object " - . "called $scene_controller defined. Ignoring SCENE_BUILD entry." - ); + ::print_log( "[Read_Table_A] ERROR: There is no object " . "called $scene_controller defined. Ignoring SCENE_BUILD entry." ); } } } else { - ::print_log( "[Read_Table_A] ERROR: There is no controller " - . "defined for $scene. Ignoring SCENE_BUILD entry." ); + ::print_log( "[Read_Table_A] ERROR: There is no controller " . "defined for $scene. Ignoring SCENE_BUILD entry." ); } } return $code; @@ -1790,9 +1651,8 @@ sub read_table_finish_A { # #Global validation routine: sub validate_def { my ( $type, $req_count, $req_array, $passed_values ) = @_; - my $paramNum = 0; - my $paramCount = - scalar @{$passed_values}; # Number of parameters passed on the item + my $paramNum = 0; + my $paramCount = scalar @{$passed_values}; # Number of parameters passed on the item foreach my $param_type ( @{$req_array} ) { if ( defined $$passed_values[$paramNum] @@ -1803,14 +1663,12 @@ sub validate_def { ::print_log( "[Read_Table_A] ERROR: $_[0]: $$passed_values[0], failed to match $param_type: Found \"$$passed_values[$paramNum]\", Definition skipped." ); - ::print_log( "[Read_table-A] $_[0], " - . join( ', ', @$passed_values ) ); + ::print_log( "[Read_table-A] $_[0], " . join( ', ', @$passed_values ) ); return 0; } } elsif ( $param_type eq 'boolean' ) { - ::print_log( - "Error item $paramNum in definition, should be 0 or 1") + ::print_log("Error item $paramNum in definition, should be 0 or 1") unless ( $$passed_values[$paramNum] =~ /^(0|1)$/ ); } elsif ( $param_type eq 'name' ) { @@ -1818,65 +1676,49 @@ sub validate_def { ::print_log( "[Read_Table_A] ERROR: $_[0]: $$passed_values[0], can only use characters A-z and _ Found \"$$passed_values[$paramNum]\", Definition skipped." ); - ::print_log( "[Read_table-A] $_[0], " - . join( ', ', @$passed_values ) ); + ::print_log( "[Read_table-A] $_[0], " . join( ', ', @$passed_values ) ); return 0; } } elsif ( $param_type eq 'insteon_on_level' ) { - ::print_log( - "[Read_Table_A] WARNING: $_[0]: $$passed_values[0] On level should be 0-100%, got \"$$passed_values[$paramNum]\" " - ) + ::print_log( "[Read_Table_A] WARNING: $_[0]: $$passed_values[0] On level should be 0-100%, got \"$$passed_values[$paramNum]\" " ) unless ( $$passed_values[$paramNum] =~ m/^(\d+)%?$/ && $1 <= 100 && $1 >= 0 ); } elsif ( $param_type eq 'insteon_ramp_rate' ) { - ::print_log( - "[Read_Table_A] WARNING: $_[0]: $$passed_values[0] Ramp rate should be 0-540 seconds, got \"$$passed_values[$paramNum]\" " - ) + ::print_log( "[Read_Table_A] WARNING: $_[0]: $$passed_values[0] Ramp rate should be 0-540 seconds, got \"$$passed_values[$paramNum]\" " ) unless ( $$passed_values[$paramNum] =~ m/^([.0-9]+)s?$/ && $1 <= 540 && $1 >= 0 ); } elsif ( $param_type eq 'insteon_address' ) { - my ( $x1, $x2, $x3 ) = $$passed_values[$paramNum] =~ - m/^([A-F0-9]{2})\.([A-F0-9]{2})\.([A-F0-9]{2})$/i; + my ( $x1, $x2, $x3 ) = $$passed_values[$paramNum] =~ m/^([A-F0-9]{2})\.([A-F0-9]{2})\.([A-F0-9]{2})$/i; unless ( $x1 && $x2 && $x3 ) { - ::print_log( - "[Read_Table_A] ERROR: $_[0]: $$passed_values[0] Insteon Address should be xx.xx.xx, got \"$$passed_values[$paramNum]\" " - ); - ::print_log( "[Read_table-A] $_[0], " - . join( ', ', @$passed_values ) ); + ::print_log( "[Read_Table_A] ERROR: $_[0]: $$passed_values[0] Insteon Address should be xx.xx.xx, got \"$$passed_values[$paramNum]\" " ); + ::print_log( "[Read_table-A] $_[0], " . join( ', ', @$passed_values ) ); return 0; } } elsif ( $param_type eq 'x10_address' ) { - my ( $ha, $da ) = - $$passed_values[$paramNum] =~ m/^([A-P])([0-9]{1,2})$/i; + my ( $ha, $da ) = $$passed_values[$paramNum] =~ m/^([A-P])([0-9]{1,2})$/i; unless ( $ha && $da && $da < 17 ) { ::print_log( "[Read_Table_A] ERROR: $_[0]: $$passed_values[0] X10 Address should be 2-3 characters, House code A-P, Device 1-16, got \"$$passed_values[$paramNum]\", Definition skipped." ); - ::print_log( "[Read_table-A] $_[0], " - . join( ', ', @$passed_values ) ); + ::print_log( "[Read_table-A] $_[0], " . join( ', ', @$passed_values ) ); return 0; } } else { - ::print_log( - "[Read_Table_A] WARNING: Unknown validation type: $param_type" - ); + ::print_log( "[Read_Table_A] WARNING: Unknown validation type: $param_type" ); } } else { if ( $paramNum < $req_count ) { my $pc = scalar @$passed_values; - ::print_log( - "[Read_table-A] ERROR: $_[0] $req_count parameters are required in the definition, $pc parameters found: definition skipped." - ); - ::print_log( "[Read_table-A] $_[0], " - . join( ', ', @$passed_values ) ); + ::print_log( "[Read_table-A] ERROR: $_[0] $req_count parameters are required in the definition, $pc parameters found: definition skipped." ); + ::print_log( "[Read_table-A] $_[0], " . join( ', ', @$passed_values ) ); return 0; } }