Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Venstar colortouch hplato #571

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 83 additions & 46 deletions lib/Venstar_Colortouch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ sub new {
$self->{config}->{cache_time} = 30; #TODO fix cache timeouts
$self->{config}->{cache_time} = $::config_params{venstar_config_cache_time}
if defined $::config_params{venstar_config_cache_time};
$self->{config}->{tz} = $::config_params{time_zone}
$self->{config}->{tz} =
$::config_params{time_zone}
; #TODO Need to figure out DST for print runtimes
$self->{config}->{poll_seconds} = 60;
$self->{config}->{poll_seconds} = $poll if ($poll);
Expand All @@ -70,6 +71,7 @@ sub new {
$self->{host} = $host;
$self->{debug} = 0;
$self->{loglevel} = 1;
$self->{status} = "";
$self->{timeout} = 15; #300;

$self->_init;
Expand Down Expand Up @@ -171,31 +173,25 @@ sub poll {
$self->{data}->{sensors} = $sensors;
$self->{data}->{timestamp} = time;
$self->{data}->{retry} = 0;
if ( defined $self->{child_object}->{comm} ) {
if ( $self->{child_object}->{comm}->state() ne "online" ) {
main::print_log
"[Venstar Colortouch] Communication Tracking object found. Updating..."
if ( $self->{loglevel} );
$self->{child_object}->{comm}->set( "online", 'poll' );
}
}

#if (defined $self->{child_object}->{comm}) {
# if ($self->{child_object}->{comm}->state() ne "online") {
# main::print_log "[Venstar Colortouch:". $self->{data}->{name} . "]] Communication Tracking object found. Updating from " . $self->{child_object}->{comm}->state() . " to online..." if ($self->{loglevel});
# $self->{child_object}->{comm}->set("online",'poll');
# }
#}
return ('1');
}
else {
main::print_log( "[Venstar Colortouch:"
. $self->{data}->{name}
. "] Problem retrieving poll data from "
. $self->{host} );
$self->{data}->{retry}++;
if ( defined $self->{child_object}->{comm} ) {
if ( $self->{child_object}->{comm}->state() ne "offline" ) {
main::print_log
"[Venstar Colortouch] Communication Tracking object found. Updating..."
if ( $self->{loglevel} );
$self->{child_object}->{comm}->set( "offline", 'poll' );
}
}
return ('0');

#} else {
# main::print_log("[Venstar Colortouch:". $self->{data}->{name} . "] Problem retrieving poll data from " . $self->{host});
# $self->{data}->{retry}++;
# if (defined $self->{child_object}->{comm}) {
# if ($self->{child_object}->{comm}->state() ne "offline") {
# main::print_log "[Venstar Colortouch:". $self->{data}->{name} . "] Communication Tracking object found. Updating from " . $self->{child_object}->{comm}->state() . " to offline..." if ($self->{loglevel});
# $self->{child_object}->{comm}->set("offline",'poll');
# }
# }
# return ('0');
}

}
Expand Down Expand Up @@ -229,21 +225,29 @@ sub _get_JSON_data {
. "] Warning, failed to get data. Response code $responseCode"
);
if ( defined $self->{child_object}->{comm} ) {
if ( $self->{child_object}->{comm}->state() ne "offline" ) {
main::print_log
"[Venstar Colortouch] Communication Tracking object found. Updating..."
if ( $self->{status} eq "online" ) {
main::print_log "[Venstar Colortouch:"
. $self->{data}->{name}
. "] Communication Tracking object found. Updating from "
. $self->{child_object}->{comm}->state()
. " to offline..."
if ( $self->{loglevel} );
$self->{status} = "offline";
$self->{child_object}->{comm}->set( "offline", 'poll' );
}
}
return ('0');
}
else {
if ( defined $self->{child_object}->{comm} ) {
if ( $self->{child_object}->{comm}->state() ne "online" ) {
main::print_log
"[Venstar Colortouch] Communication Tracking object found. Updating..."
if ( $self->{status} eq "offline" ) {
main::print_log "[Venstar Colortouch:"
. $self->{data}->{name}
. "] Communication Tracking object found. Updating from "
. $self->{child_object}->{comm}->state()
. " to online..."
if ( $self->{loglevel} );
$self->{status} = "online";
$self->{child_object}->{comm}->set( "online", 'poll' );
}
}
Expand Down Expand Up @@ -273,6 +277,28 @@ sub _get_JSON_data {
sub _push_JSON_data {
my ( $self, $type, $params ) = @_;

my ( @fan, @fanstate, @modename, @statename, @schedule, @home );
$fan[0] = "auto";
$fan[1] = "on";
$fanstate[0] = "off";
$fanstate[1] = "running";
$home[0] = "home";
$home[1] = "away";
$modename[0] = "off";
$modename[1] = "heating";
$modename[2] = "cooling";
$modename[3] = "auto";
$statename[0] = "idle";
$statename[1] = "heating";
$statename[2] = "cooling";
$statename[3] = "lockout";
$statename[4] = "error";
$schedule[0] = "morning (occupied1)";
$schedule[1] = "day (occupied2)";
$schedule[2] = "evening (occupied3)";
$schedule[3] = "night (occupied4)";
$schedule[255] = "inactive";

my $cmd;

#print "VCT DB: $params\n";
Expand Down Expand Up @@ -317,7 +343,7 @@ sub _push_JSON_data {
if ( $caway ne $away ) {
main::print_log( "[Venstar Colortouch:"
. $self->{data}->{name}
. "] Changing Away from $caway to $away" );
. "] Changing Away from $home[$caway] to $home[$away]" );
$newaway = $away;
}
else {
Expand All @@ -327,7 +353,8 @@ sub _push_JSON_data {
if ( $csched ne $sched ) {
main::print_log( "[Venstar Colortouch:"
. $self->{data}->{name}
. "] Changing Schedule from $csched to $sched" );
. "] Changing Schedule from $schedule[$csched] to $schedule[$sched]"
);
$newsched = $sched;
}
else {
Expand Down Expand Up @@ -355,7 +382,7 @@ sub _push_JSON_data {
$cmd =
"tempunits=$newunits&away=$newaway&schedule=$newsched&hum_setpoint=$newhumsp&dehum_setpoint=$newdehumsp";
main::print_log( "Sending Settings command $cmd to " . $self->{host} )
; # if $self->{debug};
if $self->{debug};

}
elsif ( $type eq 'control' ) {
Expand Down Expand Up @@ -384,13 +411,15 @@ sub _push_JSON_data {

main::print_log(
"data1=$isSuccessResponse,$cmode,$cfan,$cheattemp,$ccooltemp,$setpointdelta"
); #TODO pass object to get debug
main::print_log("data2=$mode,$fan,$heattemp,$cooltemp"); #TODO debug
) if $self->{debug}; #TODO pass object to get debug
main::print_log("data2=$mode,$fan,$heattemp,$cooltemp")
if $self->{debug}; #TODO debug

if ( $cmode ne $mode ) {
main::print_log( "[Venstar Colortouch:"
. $self->{data}->{name}
. "] Changing mode from $cmode to $mode" );
. "] Changing mode from $modename[$cmode] to $modename[$mode]"
);
$newmode = $mode;
}
else {
Expand All @@ -400,7 +429,7 @@ sub _push_JSON_data {
if ( $cfan ne $fan ) {
main::print_log( "[Venstar Colortouch:"
. $self->{data}->{name}
. "] Changing fan from $cfan to $fan" );
. "] Changing fan from $fanstate[$cfan] to $fanstate[$fan]" );
$newfan = $fan;
}
else {
Expand Down Expand Up @@ -443,10 +472,10 @@ sub _push_JSON_data {
$newheatsp = $cheattemp;
}

if ( ( $newheatsp - $newcoolsp ) < $setpointdelta ) {
if ( ( $newheatsp - $newcoolsp ) > $setpointdelta ) {
main::print_log( "[Venstar Colortouch:"
. $self->{data}->{name}
. "] Error: Cooling and Heating setpoints need to be less than setpoint $setpointdelta"
. "] Error: Cooling ($newcoolsp) and Heating ($newheatsp) setpoints need to be less than setpoint $setpointdelta"
);
main::print_log( "[Venstar Colortouch:"
. $self->{data}->{name}
Expand Down Expand Up @@ -487,20 +516,28 @@ sub _push_JSON_data {
. $self->{data}->{name}
. "] Warning, failed to push data. Response code $responseCode" );
if ( defined $self->{child_object}->{comm} ) {
if ( $self->{child_object}->{comm}->state() ne "offline" ) {
main::print_log
"[Venstar Colortouch] Communication Tracking object found. Updating..."
if ( $self->{status} eq "online" ) {
main::print_log "[Venstar Colortouch:"
. $self->{data}->{name}
. "] Communication Tracking object found. Updating from "
. $self->{child_object}->{comm}->state()
. " to offline..."
if ( $self->{loglevel} );
$self->{status} = "offline";
$self->{child_object}->{comm}->set( "offline", 'poll' );
}
}
}
else {
if ( defined $self->{child_object}->{comm} ) {
if ( $self->{child_object}->{comm}->state() ne "online" ) {
main::print_log
"[Venstar Colortouch] Communication Tracking object found. Updating..."
if ( $self->{status} eq "offline" ) {
main::print_log "[Venstar Colortouch:"
. $self->{data}->{name}
. "] Communication Tracking object found. Updating from "
. $self->{child_object}->{comm}->state()
. " to online..."
if ( $self->{loglevel} );
$self->{status} = "online";
$self->{child_object}->{comm}->set( "online", 'poll' );
}
}
Expand Down