Skip to content

Commit

Permalink
v1.0.12 Aurora
Browse files Browse the repository at this point in the history
  • Loading branch information
hplato committed Jun 16, 2017
2 parents 78e4b11 + 555535f commit 54902b5
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 108 deletions.
63 changes: 26 additions & 37 deletions lib/OpenSprinkler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ use Data::Dumper;
# TODO
# - be nice to pull runtimes and store it into a dbm file, or maybe RRD?
# - disabling the opensprinkler doesn't turn off any running stations.
# - the architecture can create pauses -- long term adopt Kevin's approach w/ Nests
# - the architecture can create pauses -- long term adopt Venstar process_item model
# - no ability to print logs. The built-in web interface does this well already

# v1.0 release
# v1.1 (May 2016) - added ability to change program runtimes
# v1.11 (May 2016) - removed JSON::XS dependancy
# v1.11.1 (May 2017) - changed to support logger

@OpenSprinkler::ISA = ('Generic_Item');

Expand Down Expand Up @@ -99,7 +100,7 @@ $result{9} = "unknown error";

sub new {
my ( $class, $host, $pwd, $poll ) = @_;
my $self = {};
my $self = new Generic_Item();
bless $self, $class;
$self->{data} = undef;
$self->{child_object} = undef;
Expand Down Expand Up @@ -150,8 +151,7 @@ sub _init {
for my $index ( 0 .. $#{ $stations->{snames} } ) {

#print "$index: $stations->{snames}[$index]\n";
$self->{data}->{stations}->[$index]->{name} =
$stations->{snames}[$index];
$self->{data}->{stations}->[$index]->{name} = $stations->{snames}[$index];
}

# Check to see if station is disabled, Bitwise operation
Expand All @@ -160,8 +160,7 @@ sub _init {
for my $bit ( 0 .. 7 ) {
my $station_id = ( ( $stn_dis * 8 ) + $bit );
my $disabled = substr $bin, ( 7 - $bit ), 1;
$self->{data}->{stations}->[$station_id]->{status} =
( $disabled == 0 ) ? "enabled" : "disabled";
$self->{data}->{stations}->[$station_id]->{status} = ( $disabled == 0 ) ? "enabled" : "disabled";
}
}

Expand Down Expand Up @@ -214,20 +213,16 @@ sub poll {
$self->{data}->{loc} = $vars->{loc};
$self->{data}->{options} = $options;
$self->{data}->{vars} = $vars;
$self->{data}->{info}->{state} =
( $vars->{en} == 0 ) ? "disabled" : "enabled";
$self->{data}->{info}->{waterlevel} = $options->{wl};
$self->{data}->{info}->{adjustment_method} =
( $options->{uwt} == 0 ) ? "manual" : "zimmerman";
$self->{data}->{info}->{rain_sensor_status} =
( $vars->{rs} == 0 ) ? "off" : "on";
$self->{data}->{info}->{sunrise} = $vars->{sunrise};
$self->{data}->{info}->{sunset} = $vars->{sunset};
$self->{data}->{info}->{state} = ( $vars->{en} == 0 ) ? "disabled" : "enabled";
$self->{data}->{info}->{waterlevel} = $options->{wl};
$self->{data}->{info}->{adjustment_method} = ( $options->{uwt} == 0 ) ? "manual" : "zimmerman";
$self->{data}->{info}->{rain_sensor_status} = ( $vars->{rs} == 0 ) ? "off" : "on";
$self->{data}->{info}->{sunrise} = $vars->{sunrise};
$self->{data}->{info}->{sunset} = $vars->{sunset};

for my $index ( 0 .. $#{ $stations->{sn} } ) {
print "$index: $stations->{sn}[$index]\n" if ( $self->{debug} );
$self->{data}->{stations}->[$index]->{state} =
( $stations->{sn}[$index] == 0 ) ? "off" : "on";
$self->{data}->{stations}->[$index]->{state} = ( $stations->{sn}[$index] == 0 ) ? "off" : "on";
}
for my $index ( 0 .. $#{ $programs->{pd} } ) {
my $name = $programs->{pd}[$index][5];
Expand All @@ -237,9 +232,8 @@ sub poll {
( $programs->{pd}[$index][0] % 2 == 1 )
? "enabled"
: "disabled"; #if number is odd, then bit 0 set and disabled
$self->{data}->{programs}->{$name}->{flag} =
$programs->{pd}[$index][0];
$self->{data}->{programs}->{$name}->{pid} = $index;
$self->{data}->{programs}->{$name}->{flag} = $programs->{pd}[$index][0];
$self->{data}->{programs}->{$name}->{pid} = $index;
$self->{data}->{programs}->{$name}->{data} =
"$programs->{pd}[$index][1],$programs->{pd}[$index][2],["
. join( ",", @{ $programs->{pd}[$index][3] } ) . "],["
Expand Down Expand Up @@ -509,8 +503,7 @@ sub process_data {
main::print_log(
"[OpenSprinkler] Station $index $self->{data}->{stations}->[$index]->{name} changed from $previous to $self->{data}->{stations}->[$index]->{state}"
) if ( $self->{loglevel} );
$self->{previous}->{data}->{stations}->[$index]->{state} =
$self->{data}->{stations}->[$index]->{state};
$self->{previous}->{data}->{stations}->[$index]->{state} = $self->{data}->{stations}->[$index]->{state};
if ( defined $self->{child_object}->{station}->{$index} ) {
main::print_log "Child object found. Updating..."
if ( $self->{loglevel} );
Expand All @@ -525,8 +518,7 @@ sub process_data {
if ( defined $self->{previous}->{data}->{programs}->{$key}->{status} );
if ( $previous ne $self->{data}->{programs}->{$key}->{status} ) {
main::print_log("[OpenSprinkler] Program $key changed from $previous to $self->{data}->{programs}->{$key}->{status}") if ( $self->{loglevel} );
$self->{previous}->{data}->{programs}->{$key}->{status} =
$self->{data}->{programs}->{$key}->{status};
$self->{previous}->{data}->{programs}->{$key}->{status} = $self->{data}->{programs}->{$key}->{status};
if ( defined $self->{child_object}->{program}->{$key} ) {
main::print_log "Child object found. Updating..."
if ( $self->{loglevel} );
Expand All @@ -544,8 +536,7 @@ sub process_data {
if ( $self->{previous}->{info}->{waterlevel} != $self->{data}->{info}->{waterlevel} ) {
main::print_log("[OpenSprinkler] Waterlevel changed from $self->{previous}->{info}->{waterlevel} to $self->{data}->{info}->{waterlevel}")
if ( $self->{loglevel} );
$self->{previous}->{info}->{waterlevel} =
$self->{data}->{info}->{waterlevel};
$self->{previous}->{info}->{waterlevel} = $self->{data}->{info}->{waterlevel};
if ( defined $self->{child_object}->{waterlevel} ) {
main::print_log "Child object found. Updating..."
if ( $self->{loglevel} );
Expand All @@ -557,8 +548,7 @@ sub process_data {
main::print_log(
"[OpenSprinkler] Rain Sensor changed from $self->{previous}->{info}->{rain_sensor_status} to $self->{data}->{info}->{rain_sensor_status}")
if ( $self->{loglevel} );
$self->{previous}->{info}->{rain_sensor_status} =
$self->{data}->{info}->{rain_sensor_status};
$self->{previous}->{info}->{rain_sensor_status} = $self->{data}->{info}->{rain_sensor_status};
if ( defined $self->{child_object}->{rain_sensor_status} ) {
main::print_log "Child object found. Updating..."
if ( $self->{loglevel} );
Expand All @@ -582,8 +572,7 @@ sub process_data {
main::print_log(
"[OpenSprinkler] Adjustment Method changed from $self->{previous}->{info}->{adjustment_method} to $self->{data}->{info}->{adjustment_method}")
if ( $self->{loglevel} );
$self->{previous}->{info}->{adjustment_method} =
$self->{data}->{info}->{adjustment_method};
$self->{previous}->{info}->{adjustment_method} = $self->{data}->{info}->{adjustment_method};
}

}
Expand Down Expand Up @@ -680,9 +669,9 @@ sub set_program_data {
#intervals can always come later.

return unless ( defined $self->{data}->{programs}->{$name} );
$days =~ s/\s//g; #remove whitespace
$days =~ s/\s//g; #remove whitespace
$start =~ s/\s//g;
$run =~ s/\s//g;
$run =~ s/\s//g;

#set the program to schedule weekday , fixed time
my $bin = sprintf "%08b", $self->{data}->{programs}->{$name}->{flag};
Expand Down Expand Up @@ -885,7 +874,7 @@ package OpenSprinkler_Station;
sub new {
my ( $class, $object, $number, $on_timeout ) = @_;

my $self = {};
my $self = new Generic_Item();
bless $self, $class;

$$self{master_object} = $object;
Expand Down Expand Up @@ -921,7 +910,7 @@ package OpenSprinkler_Program;
sub new {
my ( $class, $object, $name, $maxlimit ) = @_;

my $self = {};
my $self = new Generic_Item();
bless $self, $class;

$$self{master_object} = $object;
Expand Down Expand Up @@ -977,7 +966,7 @@ package OpenSprinkler_Comm;
sub new {
my ( $class, $object ) = @_;

my $self = {};
my $self = new Generic_Item();
bless $self, $class;

$$self{master_object} = $object;
Expand All @@ -1003,7 +992,7 @@ package OpenSprinkler_Waterlevel;
sub new {
my ( $class, $object ) = @_;

my $self = {};
my $self = new Generic_Item();
bless $self, $class;

$$self{master_object} = $object;
Expand All @@ -1030,7 +1019,7 @@ package OpenSprinkler_Rainstatus;
sub new {
my ( $class, $object ) = @_;

my $self = {};
my $self = new Generic_Item();
bless $self, $class;

$$self{master_object} = $object;
Expand Down
23 changes: 12 additions & 11 deletions lib/Venstar_Colortouch.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package Venstar_Colortouch;

# v2.1
# v2.1.1

#added in https support and don't retry commands that have a valid error reason code. Only retry if the device doesn't respond. (ie error 500)

Expand Down Expand Up @@ -41,6 +41,7 @@ use Data::Dumper;
# v1.4.1 - API v5, working schedule, humidity setpoints
# v2.0 - Background process
# v2.1 - fixed up some problems reconnecting to stat
# v2.1.1 - added in logger ability

# Notes
# - State can only be set by stat. Set mode will change the mode.
Expand Down Expand Up @@ -78,7 +79,7 @@ $rest{settings} = "settings";
sub new {
my ( $class, $host, $poll, $options ) = @_;
$options = "" unless ( defined $options );
my $self = {};
my $self = new Generic_Item();
bless $self, $class;
$self->{data} = undef;
$self->{api_ver} = 0;
Expand Down Expand Up @@ -2020,7 +2021,7 @@ package Venstar_Colortouch_Temp;
sub new {
my ( $class, $object ) = @_;

my $self = {};
my $self = new Generic_Item();
bless $self, $class;

$$self{master_object} = $object;
Expand Down Expand Up @@ -2050,7 +2051,7 @@ package Venstar_Colortouch_Fan;
sub new {
my ( $class, $object ) = @_;

my $self = {};
my $self = new Generic_Item();
bless $self, $class;
push( @{ $$self{states} }, 'off', 'on' );
$self->{current_mode} = "";
Expand Down Expand Up @@ -2099,7 +2100,7 @@ package Venstar_Colortouch_Humidity;
sub new {
my ( $class, $object ) = @_;

my $self = {};
my $self = new Generic_Item();
bless $self, $class;

$$self{master_object} = $object;
Expand All @@ -2125,7 +2126,7 @@ package Venstar_Colortouch_Humidity_sp;
sub new {
my ( $class, $object ) = @_;

my $self = {};
my $self = new Generic_Item();
bless $self, $class;

$$self{master_object} = $object;
Expand Down Expand Up @@ -2160,7 +2161,7 @@ package Venstar_Colortouch_Schedule;
sub new {
my ( $class, $object ) = @_;

my $self = {};
my $self = new Generic_Item();
bless $self, $class;

$$self{master_object} = $object;
Expand Down Expand Up @@ -2194,7 +2195,7 @@ package Venstar_Colortouch_Comm;
sub new {
my ( $class, $object ) = @_;

my $self = {};
my $self = new Generic_Item();
bless $self, $class;

$$self{master_object} = $object;
Expand All @@ -2219,7 +2220,7 @@ package Venstar_Colortouch_Mode;
sub new {
my ( $class, $object ) = @_;

my $self = {};
my $self = new Generic_Item();
bless $self, $class;

$$self{master_object} = $object;
Expand Down Expand Up @@ -2259,7 +2260,7 @@ package Venstar_Colortouch_Heat_sp;
sub new {
my ( $class, $object, $scale ) = @_;

my $self = {};
my $self = new Generic_Item();
bless $self, $class;

$$self{master_object} = $object;
Expand Down Expand Up @@ -2311,7 +2312,7 @@ package Venstar_Colortouch_Cool_sp;
sub new {
my ( $class, $object, $scale ) = @_;

my $self = {};
my $self = new Generic_Item();
bless $self, $class;

$$self{master_object} = $object;
Expand Down
26 changes: 22 additions & 4 deletions lib/ia7_utilities.pl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sub main::ia7_update_schedule {

sub ia7_update_collection {
&main::print_log("[IA7_Collection_Updater] : Starting");
my $ia7_coll_current_ver = 1.2;
my $ia7_coll_current_ver = 1.3;

my @collection_files = (
"$main::Pgm_Root/data/web/collections.json",
Expand All @@ -36,6 +36,7 @@ sub ia7_update_collection {
&main::print_log("[IA7_Collection_Updater] : Reviewing $file to current version $ia7_coll_current_ver");
my $json_data;
my $file_data;
my $updated;
eval {
$file_data = &main::file_read($file);
$json_data = decode_json($file_data); #HP, wrap this in eval to prevent MH crashes
Expand All @@ -45,11 +46,11 @@ sub ia7_update_collection {
&main::print_log("[IA7_Collection_Updater] : WARNING: decode_json failed for $file. Please check this file!");
}
else {
my $updated = 0;
$updated = 0;

if ( ( !defined $json_data->{meta}->{version} )
or ( $json_data->{meta}->{version} < 1.2 ) )
{ #IA7 v1.2 required change
{ #IA7 v1.2 required change
$json_data->{700}->{user} = '$Authorized'
unless ( defined $json_data->{700}->{user} );
my $found = 0;
Expand All @@ -59,9 +60,26 @@ sub ia7_update_collection {
push( @{ $json_data->{500}->{children} }, 700 )
unless ($found);
$json_data->{meta}->{version} = "1.2";
&main::print_log("[IA7_Collection_Updater] : Updating $file to version 1.2");
&main::print_log("[IA7_Collection_Updater] : Updating $file to version 1.2 (MH 4.2 IA7 v1.2.100 support)");
$updated = 1;
}
if ( $json_data->{meta}->{version} < 1.3 ) {
#IA7 v1.4 required change
#convert back to a file so we can globally change links
my $file_data2 = to_json( $json_data, { utf8 => 1, pretty => 1 } );
$file_data2 =~ s/\"link\"[\s+]:[\s+]\"\/ia7\/\#path=\/vars\"/\"link\" : \"\/ia7\/\#path\=\/vars_global\"/g;
$file_data2 =~ s/\"link\"[\s+]:[\s+]\"\/ia7\/\#path=\/vars\/Save\"/\"link\" : \"\/ia7\/\#path\=\/vars_save\"/g;
eval {
$json_data = decode_json($file_data2); #HP, wrap this in eval to prevent MH crashes
};
if ($@) {
&main::print_log("[IA7_Collection_Updater] : WARNING: decode_json failed for v1.3 update.");
} else {
$json_data->{meta}->{version} = "1.3";
&main::print_log("[IA7_Collection_Updater] : Updating $file to version 1.3 (MH 4.3 IA7 v1.4.400 support)");
$updated = 1;
}
}
if ($updated) {
my $json_newdata = to_json( $json_data, { utf8 => 1, pretty => 1 } );
my $backup_file = $file . ".t" . int( ::get_tickcount() / 1000 ) . ".backup";
Expand Down
Loading

0 comments on commit 54902b5

Please sign in to comment.