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

Prevent crash from corrupt thermostat record #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
27 changes: 24 additions & 3 deletions bin/max
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ sub do_set {
my ($room_id, $setpoint) = @_;
$room_id ||= 0;

my $usage = "Usage: $0 set <roomid> <eco|comfort|temperature per 0.5>\n";
my $usage = "Usage: $0 set <roomid> <boost|eco|comfort|temperature per 0.5>\n";
$room_id eq 'all' or _valid_uint8($room_id) && $room_id > 0 or die $usage;

$setpoint eq 'eco' or $setpoint eq 'comfort'
$setpoint eq 'eco' or $setpoint eq 'comfort' or $setpoint eq 'boost'
or _valid_temperature($setpoint) or die $usage;

$max ||= Max->connect($host);
Expand All @@ -114,7 +114,28 @@ sub do_set {
$room->devices or warn "No devices in " . $room->display_name . ".\n";
my $t = $setpoint =~ /eco|comfort/ ? $room->get_preset($setpoint) : $setpoint;
printf "Setting %s temperature to %s.\n", $room->display_name, $t;
$room->setpoint($t) or die "Setting temperature failed.\n";
if($setpoint eq 'boost'){
$room->boost() or die "Boosting temperature failed.\n";
}else{
$room->setpoint($t) or die "Setting temperature failed.\n";
}
}
print "Done.\n";
}

sub do_boost {
my ($room_id) = @_;
$room_id ||= 0;

my $usage = "Usage: $0 boost <roomid>\n";
$room_id eq 'all' or _valid_uint8($room_id) && $room_id > 0 or die $usage;

$max ||= Max->connect($host);

for my $room ($room_id eq 'all' ? $max->rooms : $max->room($room_id)) {
$room->devices or warn "No devices in " . $room->display_name . ".\n";
printf "Boosting %s.\n", $room->display_name;
$room->boost() or die "Boosting temperature failed.\n";
}
print "Done.\n";
}
Expand Down
42 changes: 22 additions & 20 deletions lib/Max.pm
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,28 @@ sub _process_L {
my $device = $self->{devices}{$addr}
or warn "Unexpected device " . unpack("H*", $addr);

$device->_set(flags => {
link_error => !! ($flags & 0x0040),
battery => !! ($flags & 0x0080),
uninitialized => ! ($flags & 0x0200),
error => !! ($flags & 0x0800),
invalid => ! ($flags & 0x1000),
});

if (defined $setpoint) { # not for button/shutter
$temp |= !!($setpoint & 0x80) << 8;
$setpoint &= 0x7F;

$temp = $date if $temp == 0 and $date > 0 and $device->has_temperature;

$device->_set(
mode => $flags & 0x0003,
setpoint => $setpoint / 2,
temperature => $temp / 10,
valve => $valve,
);
if (defined $device) {
$device->_set(flags => {
link_error => !! ($flags & 0x0040),
battery => !! ($flags & 0x0080),
uninitialized => ! ($flags & 0x0200),
error => !! ($flags & 0x0800),
invalid => ! ($flags & 0x1000),
});

if (defined $setpoint) { # not for button/shutter
$temp |= !!($setpoint & 0x80) << 8;
$setpoint &= 0x7F;

$temp = $date if $temp == 0 and $date > 0 and $device->has_temperature;

$device->_set(
mode => $flags & 0x0003,
setpoint => $setpoint / 2,
temperature => $temp / 10,
valve => $valve,
);
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions lib/Max/Room.pm
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ sub setpoint {
return $self->_send_radio(0x40, sprintf "%02x", $t2 | 0x40);
}

sub boost {
my ($self) = @_;
my $t2 = $self->_get_setpoint * 2;
return $self->_send_radio(0x40, sprintf "%02x", $t2 | 0xc0);
}

sub too_cold {
my ($self, $maxdelta) = @_;
$maxdelta ||= 0;
Expand Down