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

Added support for batterystatus #13

Merged
merged 1 commit into from
Jun 3, 2018
Merged
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
12 changes: 11 additions & 1 deletion maxcube/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
MAX_WINDOW_SHUTTER, \
MAX_WALL_THERMOSTAT, \
MAX_DEVICE_MODE_AUTOMATIC, \
MAX_DEVICE_MODE_MANUAL
MAX_DEVICE_MODE_MANUAL, \
MAX_DEVICE_BATTERY_OK, \
MAX_DEVICE_BATTERY_LOW
from maxcube.room import MaxRoom
from maxcube.thermostat import MaxThermostat
from maxcube.wallthermostat import MaxWallThermostat
Expand Down Expand Up @@ -207,6 +209,10 @@ def parse_l_message(self, message):

device = self.device_by_rf(device_rf_address)

if device:
bits1, bits2 = struct.unpack('BB', bytearray(data[pos + 5: pos + 7]))
device.battery = self.resolve_device_battery(bits2)

# Thermostat or Wall Thermostat
if device and (self.is_thermostat(device) or self.is_wallthermostat(device)):
device.target_temperature = (data[pos + 8] & 0x7F) / 2.0
Expand Down Expand Up @@ -281,6 +287,10 @@ def set_temperature_mode(self, thermostat, temperature, mode):
def resolve_device_mode(cls, bits):
return (bits & 3)

@classmethod
def resolve_device_battery(cls, bits):
return (bits >> 7)

@classmethod
def is_thermostat(cls, device):
return device.type == MAX_THERMOSTAT or device.type == MAX_THERMOSTAT_PLUS
Expand Down
3 changes: 3 additions & 0 deletions maxcube/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
MAX_DEVICE_MODE_VACATION = 2
MAX_DEVICE_MODE_BOOST = 3

MAX_DEVICE_BATTERY_OK = 0
MAX_DEVICE_BATTERY_LOW = 1

class MaxDevice(object):
def __init__(self):
Expand All @@ -18,3 +20,4 @@ def __init__(self):
self.room_id = None
self.name = None
self.serial = None
self.battery = None