From 79662026d8dcfac2d5806569341f554d245c1c91 Mon Sep 17 00:00:00 2001 From: Tobias Sachs Date: Wed, 30 Mar 2016 15:38:24 +0200 Subject: [PATCH 1/4] Add a PLCBUS_Shutter object --- lib/PLCBUS.pm | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/lib/PLCBUS.pm b/lib/PLCBUS.pm index af40e3dd1..50d4e47ef 100644 --- a/lib/PLCBUS.pm +++ b/lib/PLCBUS.pm @@ -1905,6 +1905,52 @@ package PLCBUS_2026; package PLCBUS_2263; @PLCBUS_2263::ISA = ('PLCBUS_LightItem'); +package PLCBUS_2268; +@PLCBUS_2268::ISA = ('PLCBUS_Item'); +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); + $self->set_states(qw |on off|); + return $self; +} + +package PLCBUS_Shutter; +@PLCBUS_Shutter::ISA = ('PLCBUS_Item'); +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); + $self->set_states(qw |up down|); + return $self; +} +sub set{ + my ( $self, $new_state, $setby, $respond ) = @_; + my $home = $self->{home}; + my $unit = $self->{unit}; + my $new_cmd = $new_state; + if ($new_state eq 'up'){ + $new_cmd = 'on'; + } + if ($new_state eq 'down'){ + $new_cmd = 'off'; + } + + PLCBUS_Item::set($self, $new_cmd, $setby, $respond); +} + +sub _set{ + my ( $self, $new_state, $setby, $respond ) = @_; + my $new_cmd = $new_state; + if ($new_state eq 'on'){ + $new_cmd = 'up'; + } + if ($new_state eq 'off'){ + $new_cmd = 'donw'; + } + + PLCBUS_Item::_set($self, $new_cmd, $setby, $respond); + +} + package PLCBUS_Scene; @PLCBUS_Scene::ISA = ('PLCBUS_Item'); use Data::Dumper qw(Dumper); From 729946ba2944479e943df7d5cec1d9aded887ba2 Mon Sep 17 00:00:00 2001 From: Tobias Sachs Date: Tue, 5 Apr 2016 11:34:12 +0200 Subject: [PATCH 2/4] requeue timed out commands up to 2 additional times --- lib/PLCBUS.pm | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/PLCBUS.pm b/lib/PLCBUS.pm index 50d4e47ef..bc905e3fd 100644 --- a/lib/PLCBUS.pm +++ b/lib/PLCBUS.pm @@ -218,14 +218,14 @@ my %cmd_to_hex = ( cmd => 0x1A, flags => 0x00, data => 1, - description => "Report the Signal Stren gth. *", + description => "Report the Signal Strength. *", expected_response => undef, }, report_noise_strength => { cmd => 0x1B, flags => 0x00, data => 1, - description => "Report the Noise Str ength. *", + description => "Report the Noise Strength. *", expected_response => undef, }, get_all_id_pulse => { @@ -807,20 +807,38 @@ sub _check_current_command() { } my $delete_cmd = 0; + my $retry_cmd = 0; if ( $self->_is_current_command_complete() ) { $delete_cmd = 1; } elsif ( $self->_has_current_command_timeout() ) { $delete_cmd = 1; + if (!$self->{current_cmd}->{retry} + || $self->{current_cmd}->{retry} lt 2){ + $retry_cmd = 1; + $self->{current_cmd}->{retry}++; + _log("Requeuing after timeout. Retry=". $self->{current_cmd}->{retry}); + } + else{ + _log("Retries exceeded. Won't requeue."); + } } if ($delete_cmd) { + my $cmd = $self->{current_cmd}; $self->{current_cmd} = undef; + if ($retry_cmd){ + if(grep {$_->{home} == $cmd->{home} && $_->{unit} == $cmd->{unit} } @{$self->{command_queue}}) { + _log("Won't requeue. Queue already contains new command for $cmd->{home}$cmd->{unit}."); + } + else{ + $self->queue_command($cmd); + } + } return 1; } return 0; - } sub _can_transmit() { From b91a4b64ba20b6623319a312e8e63420c69d02cb Mon Sep 17 00:00:00 2001 From: Tobias Sachs Date: Wed, 6 Apr 2016 08:44:09 +0200 Subject: [PATCH 3/4] Make PLCBUS Shuttor modules use up/down states instead of on/off --- lib/PLCBUS.pm | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/PLCBUS.pm b/lib/PLCBUS.pm index bc905e3fd..5af5eaab7 100644 --- a/lib/PLCBUS.pm +++ b/lib/PLCBUS.pm @@ -828,7 +828,7 @@ sub _check_current_command() { my $cmd = $self->{current_cmd}; $self->{current_cmd} = undef; if ($retry_cmd){ - if(grep {$_->{home} == $cmd->{home} && $_->{unit} == $cmd->{unit} } @{$self->{command_queue}}) { + if(grep {$_->{home} eq $cmd->{home} && $_->{unit} == $cmd->{unit} } @{$self->{command_queue}}) { _log("Won't requeue. Queue already contains new command for $cmd->{home}$cmd->{unit}."); } else{ @@ -1236,6 +1236,9 @@ sub generate_code(@) { elsif ( $type =~ /^PLCBUS_Scene.*/i ) { $object = "PLCBUS_Scene('$name', '$home','$unit', '$grouplist')"; } + elsif ( $type =~ /^PLCBUS_Shutter.*/i ) { + $object = "PLCBUS_Shutter('$name', '$home','$unit', '$grouplist')"; + } elsif ( $type =~ /^PLCBUS.*/i ) { _log( "Unknown PLCBUS device type '$type'. Creating generic PLCBUS item"); @@ -1937,36 +1940,36 @@ package PLCBUS_Shutter; sub new { my $class = shift; my $self = $class->SUPER::new(@_); - $self->set_states(qw |up down|); + $self->set_states(qw |up down status_req|); return $self; } + sub set{ - my ( $self, $new_state, $setby, $respond ) = @_; + my ( $self, $state, $setby, $respond ) = @_; my $home = $self->{home}; my $unit = $self->{unit}; - my $new_cmd = $new_state; - if ($new_state eq 'up'){ - $new_cmd = 'on'; + my $new_state = $state; + if ($state eq 'up'){ + $new_state = 'off'; } - if ($new_state eq 'down'){ - $new_cmd = 'off'; + if ($state eq 'down'){ + $new_state = 'on'; } - PLCBUS_Item::set($self, $new_cmd, $setby, $respond); + PLCBUS_Item::set($self, $new_state, $setby, $respond); } sub _set{ - my ( $self, $new_state, $setby, $respond ) = @_; - my $new_cmd = $new_state; - if ($new_state eq 'on'){ - $new_cmd = 'up'; + my ( $self, $state, $setby, $respond ) = @_; + my $new_state = $state; + if ($state eq 'on'){ + $new_state = 'down'; } - if ($new_state eq 'off'){ - $new_cmd = 'donw'; + elsif ($state eq 'off'){ + $new_state = 'up'; } - PLCBUS_Item::_set($self, $new_cmd, $setby, $respond); - + PLCBUS_Item::_set($self, $new_state, $setby, $respond); } package PLCBUS_Scene; From 55a4431d738fc0951a6e60e752b0461009e2a606 Mon Sep 17 00:00:00 2001 From: Tobias Sachs Date: Tue, 10 May 2016 20:12:55 +0200 Subject: [PATCH 4/4] Add abillity to use individual 1-/3-phase mode per device If a plcbus item is added to one of the the special groups 'OnePhase' or 'ThreePhase', the approppriate command mode for this device will be use. (see help section PLCBUS ITEMS for more details) --- lib/PLCBUS.pm | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/PLCBUS.pm b/lib/PLCBUS.pm index 5af5eaab7..20e3fe081 100644 --- a/lib/PLCBUS.pm +++ b/lib/PLCBUS.pm @@ -1476,9 +1476,16 @@ the misterhouse log for the result of those commands. There are 3 special voice command states '1_phase', '3-phase' and 'use_mh_ini_phase_mode' to use a specific phase mode for one unit. This command -is stored per unit, and is also restored between misterhouse restarts. -'use_mh_ini_phase_mode' deletes the setting and the phase mode specified in +is stored per unit, and is also restored between misterhouse restarts. But won't +survive a reboot. Another way to permanently override the phase setting is to +add the item either to the group onephase or threephase to override the mh.ini +setting 'use_mh_ini_phase_mode' deletes the setting and the phase mode specified in mh.ini is used. +Phase to use is determined in the following order: + * use value set from voice command + * if not set check if its part of a phase specific group + * the the mh ini setting is used + * if mh.ini setting is not set the default 1 Phase is used =head1 SETTING UP A NEW PLCBUS MODULE @@ -1884,6 +1891,14 @@ sub _get_phase_mode { $mode = $self->{phase_override}; $self->_logd("using module specific phase mode '$mode'"); } + elsif ($self->{groups} && $self->{groups} =~ /onephase/i){ + $mode = 1; + $self->_logd("is part of onephase group using mode '$mode'"); + } + elsif ($self->{groups} && $self->{groups} =~ /threephase/i){ + $mode = 3; + $self->_logd("is part of threephase group using mode '$mode'"); + } else { $mode = $::config_parms{plcbus_phase_mode}; if ( !$mode ) {