Skip to content

Commit

Permalink
Revert "Merge pull request #23 from waynieack/ActionsOnGoogle"
Browse files Browse the repository at this point in the history
This reverts commit 3ec6249, reversing
changes made to 90f59e7.
  • Loading branch information
Wayne Gatlin committed Apr 23, 2021
1 parent ca118e5 commit 7422319
Showing 1 changed file with 31 additions and 105 deletions.
136 changes: 31 additions & 105 deletions lib/AoGSmartHome_Items.pm
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ sub set_state {
}
elsif ( ref $sub eq 'CODE' ) {
my $mh_object = ::get_object_by_name($realname);
&main::print_log("[AoGSmartHome] Invalid device $realname; ignoring AoG item.") if ( !defined $mh_object );
return undef if !defined $mh_object;

print STDERR "[AoGSmartHome] Debug: running sub $sub(set, $state)\n" if $main::Debug{'aog'};
Expand All @@ -254,7 +253,6 @@ sub set_state {
#

my $mh_object = ::get_object_by_name($realname);
&main::print_log("[AoGSmartHome] Invalid device $realname; ignoring AoG item.") if ( !defined $mh_object );
return undef if !defined $mh_object;

if ( ($mh_object->isa('Insteon::DimmableLight')
Expand Down Expand Up @@ -293,7 +291,6 @@ sub get_state {
}
elsif ( ref $statesub eq 'CODE' ) {
my $mh_object = ::get_object_by_name($realname);
&main::print_log("[AoGSmartHome] Invalid device $realname; ignoring AoG item.") if ( !defined $mh_object );
return undef if !defined $mh_object;

my $debug = "[AoGSmartHome] Debug: get_state() running sub: $statesub('$realname') - ";
Expand All @@ -307,7 +304,6 @@ sub get_state {
#

my $mh_object = ::get_object_by_name($realname);
&main::print_log("[AoGSmartHome] Invalid device $realname; ignoring AoG item.") if ( !defined $mh_object );
return undef if !defined $mh_object;

my $cstate = $mh_object->$statesub();
Expand Down Expand Up @@ -454,12 +450,9 @@ EOF
# the device has the "Brightness" trait. Other types of dimmable
# objects will have to be added here (right now we only check for
# INSTEON and X10 dimmable lights).
&main::print_log("[AoGSmartHome] Object Name: ". $self->{'uuids'}->{$uuid}->{'realname'} ."\n");
my $mh_object = ::get_object_by_name($self->{'uuids'}->{$uuid}->{'realname'});
&main::print_log("[AoGSmartHome] Invalid device ".$self->{'uuids'}->{$uuid}->{'realname'}."; ignoring AoG item.") if ( !defined $mh_object );
return undef if !defined $mh_object;

if ( (defined $mh_object) && ($mh_object->isa('Insteon::DimmableLight') || $mh_object->can('state_level')) ) {
if ($mh_object->isa('Insteon::DimmableLight')
|| $mh_object->can('state_level') ) {
$response .= <<EOF;
"action.devices.traits.Brightness",
EOF
Expand Down Expand Up @@ -520,11 +513,9 @@ EOF
$response .= <<EOF;
},
EOF
} elsif ( $type eq 'thermostat') {
}
elsif ( $type eq 'thermostat') {
my $mh_object = ::get_object_by_name($self->{'uuids'}->{$uuid}->{'realname'});
&main::print_log("[AoGSmartHome] Invalid device ".$self->{'uuids'}->{$uuid}->{'realname'}."; ignoring AoG item.") if ( !defined $mh_object );
return undef if !defined $mh_object;

if (!$mh_object->isa('Insteon::Thermostat') ) {
&main::print_log("[AoGSmartHome] '$self->{'uuids'}->{$uuid}->{'realname'} is an unsupported thermostat; ignoring AoG item.");
next;
Expand All @@ -540,9 +531,9 @@ EOF
"name": {
"name": "$self->{'uuids'}->{$uuid}->{'name'}"
},
"willReportState": true,
"willReportState": false,
"attributes": {
"availableThermostatModes": "off,heat,cool,on,heatcool,fan-only",
"availableThermostatModes": "off,heat,cool,on",
"thermostatTemperatureUnit": "F"
},
EOF
Expand Down Expand Up @@ -634,47 +625,24 @@ EOF
}
elsif ( $self->{'uuids'}->{$uuid}->{'type'} eq 'thermostat' ) {
my $mh_object = ::get_object_by_name($self->{'uuids'}->{$uuid}->{'realname'});
&main::print_log("[AoGSmartHome] Invalid device ".$self->{'uuids'}->{$uuid}->{'realname'}."; ignoring AoG item.") if ( !defined $mh_object );
return undef if !defined $mh_object;

if ($mh_object->isa('Insteon::Thermostat') ) {
my $mode = lc($mh_object->get_mode());
$mode = 'heatcool' if ($mode =~ /auto/);

my $activeThermostatMode = lc($mh_object->get_status);
my $fanmode = lc($mh_object->get_fan_mode);
if ($activeThermostatMode =~ /cooling/) {
$activeThermostatMode = 'cool';
} elsif ($activeThermostatMode =~ /heating/) {
$activeThermostatMode = 'heat';
} elsif ( ( $fanmode =~ /always on/) and ( $activeThermostatMode =~ /off/ ) ) {
$activeThermostatMode = 'fan-only';
} else {
$activeThermostatMode = 'none';
}
my $mode = $mh_object->get_mode();

my $temp_setpoint;
if ($mode eq 'cool') {
$temp_setpoint = '"thermostatTemperatureSetpoint": '. &FtoC($mh_object->get_cool_sp).',';
} elsif ($mode eq 'heat') {
$temp_setpoint = '"thermostatTemperatureSetpoint": '. &FtoC($mh_object->get_heat_sp).',';
} elsif ($mode eq 'heatcool') {
$temp_setpoint = '"thermostatTemperatureSetpointHigh": '. &FtoC($mh_object->get_cool_sp).','."\n";
$temp_setpoint .= '"thermostatTemperatureSetpointLow": '. &FtoC($mh_object->get_heat_sp).',';
$temp_setpoint = $mh_object->get_cool_sp();
} else {
$temp_setpoint = $mh_object->get_heat_sp();
}

my $temp_ambient = &FtoC($mh_object->get_temp);
my $thermostatHumidityAmbient = $mh_object->get_humid;


my $temp_ambient = $mh_object->get_temp();

$response .= <<EOF;
"$uuid": {
"online": true,
"thermostatMode": "$mode",
"activeThermostatMode": "$activeThermostatMode",
$temp_setpoint
"thermostatTemperatureAmbient": $temp_ambient,
"thermostatHumidityAmbient": $thermostatHumidityAmbient,
"status": "SUCCESS"
"thermostatTemperatureSetpoint": "$temp_setpoint",
"thermostatTemperatureAmbient": "$temp_ambient",
},
EOF
}
Expand All @@ -683,6 +651,7 @@ EOF

next;
}

#
# The device is a light, a switch, or an outlet.
#
Expand Down Expand Up @@ -714,8 +683,6 @@ EOF
# If the device is dimmable we provided the "Brightness" trait, so we
# have to supply the "brightness" state.
my $mh_object = ::get_object_by_name($self->{'uuids'}->{$uuid}->{'realname'});
&main::print_log("[AoGSmartHome] Invalid device ".$self->{'uuids'}->{$uuid}->{'realname'}."; ignoring AoG item.") if ( !defined $mh_object );
return undef if !defined $mh_object;
if ($mh_object->isa('Insteon::DimmableLight')
|| $mh_object->can('state_level') ) {

Expand Down Expand Up @@ -755,19 +722,6 @@ EOF
return &main::json_page($response);
}

sub FtoC {
my ( $F ) = @_;
return ( ($F - 32) * 5/9 );
#return sprintf "%.0f", ( ($F - 32) * 5/9 );
}

sub CtoF {
my ( $F ) = @_;
#return ( (9 * $F/5) + 32 );
return sprintf "%.0f", ( (9 * $F/5) + 32 );

}

sub execute_OnOff {
my ( $self, $command ) = @_;

Expand Down Expand Up @@ -855,68 +809,40 @@ sub execute_ThermostatX {
my $realname = $self->{'uuids'}->{$device->{'id'} }->{'realname'};

my $mh_object = ::get_object_by_name($realname);
&main::print_log("[AoGSmartHome] Invalid device $realname; ignoring AoG item.") if ( !defined $mh_object );
return undef if !defined $mh_object;

if ($mh_object->isa('Insteon::Thermostat') ) {
my $mode = lc($mh_object->get_mode);
$mode = 'heatcool' if ($mode =~ /auto/);

if ( $execution_command =~ /TemperatureSetpoint/ ) {
&main::print_log("[AoGSmartHome] Setting temp: ".&CtoF($command->{'execution'}->[0]->{'params'}->{'thermostatTemperatureSetpoint'}) ) if ( $main::Debug{'aog'} );
my $setpoint = &CtoF($command->{'execution'}->[0]->{'params'}->{'thermostatTemperatureSetpoint'});
if ( $mode eq 'cool') {
my $setpoint = $command->{'execution'}->[0]->{'params'}->{'thermostatTemperatureSetpoint'};
if ($mh_object->get_mode() eq 'cool') {
$mh_object->cool_setpoint($setpoint);
} elsif( $mode eq 'heat') {
} else {
$mh_object->heat_setpoint($setpoint);
}
} elsif ( $execution_command =~ /ThermostatTemperatureSetRange/ ) {
&main::print_log("[AoGSmartHome] Setting cool: ".&CtoF($command->{'execution'}->[0]->{'params'}->{'thermostatTemperatureSetpointHigh'})." Heat: ".&CtoF($command->{'execution'}->[0]->{'params'}->{'thermostatTemperatureSetpointLow'})) if ( $main::Debug{'aog'} );
$mh_object->cool_setpoint( &CtoF($command->{'execution'}->[0]->{'params'}->{'thermostatTemperatureSetpointHigh'}) );
$mh_object->heat_setpoint( &CtoF($command->{'execution'}->[0]->{'params'}->{'thermostatTemperatureSetpointLow'}) );
} elsif ( $execution_command =~ /ThermostatSetMode/ ) {
my $mode = $command->{'execution'}->[0]->{'params'}->{'thermostatMode'};
$mode = 'auto' if ($mode =~ /heatcool/);
$mh_object->mode($mode);
}

$mode = lc($mh_object->get_mode);
$mode = 'heatcool' if ($mode =~ /auto/);
my $activeThermostatMode = lc($mh_object->get_status());
my $fanmode = lc($mh_object->get_fan_mode);
if ($activeThermostatMode =~ /cooling/) {
$activeThermostatMode = 'cool';
} elsif ($activeThermostatMode =~ /heating/) {
$activeThermostatMode = 'heat';
} elsif ( ( $fanmode =~ /always on/) and ( $activeThermostatMode =~ /off/ ) ) {
$activeThermostatMode = 'fan-only';
} else {
$activeThermostatMode = 'none';
}

my $temp_setpoint;
if ($mode eq 'cool') {
$temp_setpoint = '"thermostatTemperatureSetpoint": '. &FtoC($mh_object->get_cool_sp).',';
} elsif ($mode eq 'heat') {
$temp_setpoint = '"thermostatTemperatureSetpoint": '. &FtoC($mh_object->get_heat_sp).',';
} elsif ($mode eq 'heatcool') {
$temp_setpoint = '"thermostatTemperatureSetpointHigh": '. &FtoC($mh_object->get_cool_sp).','."\n";
$temp_setpoint .= '"thermostatTemperatureSetpointLow": '. &FtoC($mh_object->get_heat_sp).',';
}

my $temp_ambient = &FtoC($mh_object->get_temp);
my $thermostatHumidityAmbient = $mh_object->get_humid;
my $mode = $mh_object->get_mode();

my $temp_setpoint;
if ($mode eq 'cool') {
$temp_setpoint = $mh_object->get_cool_sp();
} else {
$temp_setpoint = $mh_object->get_heat_sp();
}

my $temp_ambient = $mh_object->get_temp();

$response .= " {";
$response .= <<EOF
"ids": ["$device->{'id'}"],
"status": "SUCCESS",
"states": {
"thermostatMode": "$mode",
"activeThermostatMode": $activeThermostatMode,
$temp_setpoint
"thermostatTemperatureAmbient": $temp_ambient,
"thermostatHumidityAmbient": $thermostatHumidityAmbient
"thermostatTemperatureSetpoint": "$temp_setpoint",
"thermostatTemperatureAmbient": "$temp_ambient",
}
},
EOF
Expand Down

0 comments on commit 7422319

Please sign in to comment.