diff --git a/src/energenie/Devices.py b/src/energenie/Devices.py index 9c01236..22b311e 100644 --- a/src/energenie/Devices.py +++ b/src/energenie/Devices.py @@ -304,7 +304,7 @@ #TODO join request might be handled generically here #TODO: subclass can override and call back to this if it wants to - pass # TODO + raise RuntimeError("Method unimplemented") #TODO def send_message(self, payload): ####HERE#### interface with air_interface diff --git a/src/energenie/Registry.py b/src/energenie/Registry.py index 1bb048d..f656873 100644 --- a/src/energenie/Registry.py +++ b/src/energenie/Registry.py @@ -285,7 +285,7 @@ # seed the registry registry.add(Devices.MIHO005(device_id=0x68b), "tv") - #registry.add(Devices.ENER002(device_id=(0xC8C8C, 1)), "fan") + registry.add(Devices.ENER002(device_id=(0xC8C8C, 1)), "fan") # test the auto create mechanism import sys @@ -297,8 +297,9 @@ tv.turn_on() tv.turn_off() - #fan.turn_on() - + fan.turn_on() + fan.turn_off() + #print("tv switch:%s" % tv.has_switch()) #print("tv send:%s" % tv.can_send()) #print("tv receive:%s" % tv.can_receive()) diff --git a/src/energenie/TwoBit.py b/src/energenie/TwoBit.py index e8e4e41..ea3fa63 100644 --- a/src/energenie/TwoBit.py +++ b/src/energenie/TwoBit.py @@ -51,14 +51,14 @@ SW1_OFF_ENC = [0xEE, 0xE8] # 1110 sent as 0111 -def ashex(payload): +def ashex(payload): # -> str with hexascii bytes line = "" for b in payload: line += str(hex(b)) + " " return line -def encode_relay_message(relayState=False): +def encode_relay_message(relayState=False): # -> list of numbers """Temporary test code to prove we can turn the relay on or off""" payload = PREAMBLE #TODO: + DEFAULT_ADDR_ENC ?? @@ -72,7 +72,7 @@ return payload -def encode_test_message(pattern): +def encode_test_message(pattern): #-> list of numbers """build a test message for a D3D2D1D0 control patter""" payload = PREAMBLE + DEFAULT_ADDR_ENC pattern &= 0x0F @@ -81,7 +81,7 @@ return payload -def encode_switch_message(state, device_address=ALL_SOCKETS, house_address=None): +def encode_switch_message(state, device_address=ALL_SOCKETS, house_address=None): # -> list of numbers """Build a message to turn a switch on or off""" #print("build: state:%s, device:%d, house:%s" % (str(state), device_address, str(house_address))) @@ -133,9 +133,8 @@ #print("encoded as:%s" % ashex(payload)) return payload -#TODO: decode_switch_msg -def encode_bytes(data): +def encode_bytes(data): # -> list of numbers """Turn a list of bytes into a modulated pattern equivalent""" #print("modulate_bytes: %s" % ashex(data)) payload = [] @@ -147,7 +146,7 @@ ENCODER = [0x88, 0x8E, 0xE8, 0xEE] -def encode_bits(data, number): +def encode_bits(data, number): # -> list of numbers """Turn bits into n bytes of modulation patterns""" # 0000 00BA gets encoded as: # 128 64 32 16 8 4 2 1 @@ -166,22 +165,36 @@ return encoded -#TODO: decode_bytes +def decode_switch_message(bytes): # -> (house_address, device_index, state) + pass #TODO + # house_address, device_index, state -#TODO: decode_bits -#TODO: decode_command -# 0, False (all off) -# 0, True (all on) -# 1, False (1 off) -# 1, True (1 on) -# 2, False (2 off) -# 2, True (2 on) -# 3, False (3 off) -# 3, True (3 on) -# 4, False (4 off) -# 4, True (4 on) -# UNKNOWN (6 of the other patterns, that are not recognised) +def decode_command(bytes): #-> (device_index, state) + pass #TODO + # 0, False (all off) + # 0, True (all on) + # 1, False (1 off) + # 1, True (1 on) + # 2, False (2 off) + # 2, True (2 on) + # 3, False (3 off) + # 3, True (3 on) + # 4, False (4 off) + # 4, True (4 on) + # UNKNOWN (6 of the other patterns, that are not recognised) + + +def decode_bytes(bytes): # -> list of numbers, decoded bytes + pass #TODO + + +def decode_bits(bits, number): # -> list of bytes, decoded bits + # decode 'number' of bits held in 'bits' and return as a list of 1 or more bytes + # e.g. decode_bits(0xEE, 2) -> 0b00000011 + pass # TODO + + # END