def load_hk_items(): model = 'dasa.hartakarunitem' data = read_hk_items() out_fn = 'fixtures/hartakarunitem.json' out_fn = os.path.abspath(out_fn) create_fixture(model=model, data=data, out_fn=out_fn) load_fixture(out_fn)
def load_hk_scans(): model = 'dasa.scan' data = read_hk_scans() out_fn = 'fixtures/hartakarunscan.json' out_fn = os.path.abspath(out_fn) create_fixture(model=model, data=data, out_fn=out_fn) load_fixture(out_fn)
async def test_binary_sensors(self, _): client = get_client() await client.find_devices(True) sensor_devices = client.get_devices("binary_sensor") assert len(sensor_devices) == 1 sensor = next((el for el in sensor_devices if el.lookup_key == "ABB700D12345/ch0000")) # Test attributes assert sensor.name == "Sensor/ Schaltaktor Büro (room1)" assert sensor.serialnumber == "ABB700D12345" assert sensor.channel_id == "ch0000" assert sensor.device_info["identifiers"] == {("freeathome", "ABB700D12345")} assert sensor.device_info[ "name"] == "Sensor/ Schaltaktor Büro (ABB700D12345)" assert sensor.device_info["model"] == "Sensor/ Schaltaktor 1/1-fach" assert sensor.device_info["sw_version"] == "2.1366" assert sensor.state == "1" # Test device event await client.update_devices(load_fixture("100C_update_sensor.xml")) assert sensor.state == "0"
async def test_movement_detector(self, _): client = await self.get_client() await client.find_devices(True) sensor_devices = client.get_devices("binary_sensor") assert len(sensor_devices) == 1 # Test attributes for top button sensor_top = next((el for el in sensor_devices if el.lookup_key == "ABB700C12345/ch0000")) assert sensor_top.name == "Bewegungssensor (room1)" assert sensor_top.serialnumber == "ABB700C12345" assert sensor_top.channel_id == "ch0000" assert sensor_top.device_info["identifiers"] == {("freeathome", "ABB700C12345")} assert sensor_top.device_info[ "name"] == "Bewegungssensor (ABB700C12345)" assert sensor_top.device_info[ "model"] == "Bewegungsmelder/Schaltaktor 1-fach" assert sensor_top.device_info["sw_version"] == "2.1366" assert sensor_top.state == "1" # Test device event await client.update_devices( load_fixture("100A_update_movement_detector.xml")) assert sensor_top.state == "0"
async def test_lock(self, _): client = get_client() await client.find_devices(True) assert len(client.get_devices("light")) == 0 devices = client.get_devices("lock") assert len(devices) == 1 lock = next((el for el in devices if el.lookup_key == "ABB654612345/ch0010")) # Test attributes assert lock.name == "Door opener (room1)" assert lock.serialnumber == "ABB654612345" assert lock.channel_id == "ch0010" assert lock.device_info["identifiers"] == {("freeathome", "ABB654612345")} assert lock.device_info["name"] == "Control panel (ABB654612345)" assert lock.device_info["model"] == 'free@homeTouch 7"' assert lock.device_info["sw_version"] == "0.2.1" assert lock.state == '0' # Test datapoints await lock.lock() client.set_datapoint.assert_called_once_with("ABB654612345", "ch0010", "idp0000", "0") client.set_datapoint.reset_mock() await lock.unlock() client.set_datapoint.assert_called_once_with("ABB654612345", "ch0010", "idp0000", "1") # Test device being turned off await client.update_devices(load_fixture("unknown_update_lock.xml")) assert lock.state == '1'
async def test_light(self, _): client = get_client() await client.find_devices(True) devices = client.get_devices("light") assert len(devices) == 6 light = next((el for el in devices if el.lookup_key == "ABB2E0612345/ch000C")) # Test attributes assert light.name == "Hinten rechts (room1)" assert light.serialnumber == "ABB2E0612345" assert light.channel_id == "ch000C" assert light.device_info["identifiers"] == {("freeathome", "ABB2E0612345")} assert light.device_info["name"] == "Sensor/ Schaltaktor 8/8fach, REG (ABB2E0612345)" assert light.device_info["model"] == "Sensor/ Schaltaktor 8/8fach, REG" assert light.device_info["sw_version"] == "1.11" assert light.is_on() == False # Test datapoints await light.turn_on() client.set_datapoint.assert_called_once_with("ABB2E0612345", "ch000C", "idp0000", "1") client.set_datapoint.reset_mock() await light.turn_off() client.set_datapoint.assert_called_once_with("ABB2E0612345", "ch000C", "idp0000", "0") # Test device being turned off await client.update_devices(load_fixture("B008_update_light.xml")) assert light.is_on() == True
with patch("fah.pfreeathome.Client.__init__", return_value=None): yield @pytest.fixture(autouse=True) def mock_roomnames(): with patch("fah.pfreeathome.get_room_names", return_value={"00": { "00": "room1", "01": "room2" }}): yield @patch("fah.pfreeathome.Client.get_config", return_value=load_fixture("scene.xml")) class TestLight: async def test_scene(self, _): client = get_client() await client.find_devices(True) devices = client.get_devices("scene") assert len(devices) == 2 # First scene scene = next( (el for el in devices if el.lookup_key == "FFFF4800000F/ch0000")) # Test attributes assert scene.name == "Eigene Szene (room1)" assert scene.serialnumber == "FFFF4800000F"
async def test_binary_sensors(self, _): client = get_client() await client.find_devices(True) sensor_devices = client.get_devices("binary_sensor") assert len(sensor_devices) == 8 # Light switch sensor = next((el for el in sensor_devices if el.lookup_key == "ABB2E0612345/ch0000")) # Test attributes assert sensor.name == "Taster (room1)" assert sensor.serialnumber == "ABB2E0612345" assert sensor.channel_id == "ch0000" assert sensor.device_info["identifiers"] == {("freeathome", "ABB2E0612345")} assert sensor.device_info[ "name"] == "Sensor/ Schaltaktor 8/8fach, REG (ABB2E0612345)" assert sensor.device_info[ "model"] == "Sensor/ Schaltaktor 8/8fach, REG" assert sensor.device_info["sw_version"] == "1.11" assert sensor.state == "0" # Test device event await client.update_devices(load_fixture("B008_update_sensor.xml")) assert sensor.state == "1" # Dimming sensor dimming_sensor = next((el for el in sensor_devices if el.lookup_key == "ABB2E0612345/ch0001")) assert dimming_sensor.name == "Dimmsensor (room1)" assert dimming_sensor.serialnumber == "ABB2E0612345" assert dimming_sensor.channel_id == "ch0001" assert dimming_sensor.state == "0" # Dimming sensor dimming_sensor = next((el for el in sensor_devices if el.lookup_key == "ABB2E0612345/ch0002")) assert dimming_sensor.name == "Jalousiesensor (room1)" assert dimming_sensor.serialnumber == "ABB2E0612345" assert dimming_sensor.channel_id == "ch0002" assert dimming_sensor.state == "0" # Staircase sensor staircase_sensor = next((el for el in sensor_devices if el.lookup_key == "ABB2E0612345/ch0003")) assert staircase_sensor.name == "Treppenhauslichtsensor (room1)" assert staircase_sensor.serialnumber == "ABB2E0612345" assert staircase_sensor.channel_id == "ch0003" assert staircase_sensor.state == "0" # Force position sensor staircase_sensor = next((el for el in sensor_devices if el.lookup_key == "ABB2E0612345/ch0004")) assert staircase_sensor.name == "Sensor Zwangsstellung Ein/Aus (room1)" assert staircase_sensor.serialnumber == "ABB2E0612345" assert staircase_sensor.channel_id == "ch0004" assert staircase_sensor.state == "0" # Cover force position sensor cover_force_position_sensor = next( (el for el in sensor_devices if el.lookup_key == "ABB2E0612345/ch0005")) assert cover_force_position_sensor.name == "Jalousiezwangsstellung (room1)" assert cover_force_position_sensor.serialnumber == "ABB2E0612345" assert cover_force_position_sensor.channel_id == "ch0005" assert cover_force_position_sensor.state == "0" # Window contact sensor window_contact_sensor = next( (el for el in sensor_devices if el.lookup_key == "ABB2E0612345/ch0006")) assert window_contact_sensor.name == "Fensterkontakt (room1)" assert window_contact_sensor.serialnumber == "ABB2E0612345" assert window_contact_sensor.channel_id == "ch0006" assert window_contact_sensor.state == "0" # Movement sensor movement_sensor = next((el for el in sensor_devices if el.lookup_key == "ABB2E0612345/ch0007")) assert movement_sensor.name == "Bewegungsmelder-Sensor (room1)" assert movement_sensor.serialnumber == "ABB2E0612345" assert movement_sensor.channel_id == "ch0007" assert movement_sensor.state == "0"
with patch("fah.pfreeathome.Client.__init__", return_value=None): yield @pytest.fixture(autouse=True) def mock_roomnames(): with patch("fah.pfreeathome.get_room_names", return_value={"00": { "00": "room1", "01": "room2" }}): yield @patch("fah.pfreeathome.Client.get_config", return_value=load_fixture("100C_sensor_actuator_1gang.xml")) class TestBinarySensors: async def test_binary_sensors(self, _): client = get_client() await client.find_devices(True) sensor_devices = client.get_devices("binary_sensor") assert len(sensor_devices) == 1 sensor = next((el for el in sensor_devices if el.lookup_key == "ABB700D12345/ch0000")) # Test attributes assert sensor.name == "Sensor/ Schaltaktor Büro (room1)" assert sensor.serialnumber == "ABB700D12345" assert sensor.channel_id == "ch0000"
with patch("fah.pfreeathome.Client.__init__", return_value=None): yield @pytest.fixture(autouse=True) def mock_roomnames(): with patch("fah.pfreeathome.get_room_names", return_value={"00": { "00": "room1", "01": "room2" }}): yield @patch("fah.pfreeathome.Client.get_config", return_value=load_fixture("100A_movement_detector_actuator_1gang.xml")) class TestMovementDetectorLuxSensor: async def get_client(self): client = Client() client.devices = set() client.set_datapoint = AsyncMock() return client async def test_movement_detector_lux_sensor(self, _): client = await self.get_client() await client.find_devices(True) sensor_devices = client.get_devices("sensor") assert len(sensor_devices) == 1
with patch("fah.pfreeathome.Client.__init__", return_value=None): yield @pytest.fixture(autouse=True) def mock_roomnames(): with patch("fah.pfreeathome.get_room_names", return_value={"00": { "00": "room1", "01": "room2" }}): yield @patch("fah.pfreeathome.Client.get_config", return_value=load_fixture("1013_blind_sensor_actuator_1gang.xml")) class TestCover: async def test_cover(self, _): client = get_client() await client.find_devices(True) devices = client.get_devices("cover") assert len(client.get_devices("cover")) == 1 cover = next( (el for el in devices if el.lookup_key == "ABB700D12345/ch0003")) # Test attributes assert cover.name == "Gäste-WC (room1)" assert cover.serialnumber == "ABB700D12345" assert cover.channel_id == "ch0003" assert cover.device_info["identifiers"] == {("freeathome",
with patch("fah.pfreeathome.Client.__init__", return_value=None): yield @pytest.fixture(autouse=True) def mock_roomnames(): with patch("fah.pfreeathome.get_room_names", return_value={"00": { "00": "room1", "01": "room2" }}): yield @patch("fah.pfreeathome.Client.get_config", return_value=load_fixture("100C_sensor_actuator_1gang.xml")) class TestLight: async def test_light(self, _): client = get_client() await client.find_devices(True) devices = client.get_devices("light") assert len(devices) == 1 light = next( (el for el in devices if el.lookup_key == "ABB700D12345/ch0003")) # Test attributes assert light.name == "Büro (room1)" assert light.serialnumber == "ABB700D12345" assert light.channel_id == "ch0003" assert light.device_info["identifiers"] == {("freeathome",
print cmd if r['hartakarun_main_category']: records_category.append(r) else: del r['hartakarun_main_category'] records_maincategory.append(r) # assert type(r['position']) == type(0), r['position'] # for x in records: # print x print headers return records_maincategory, records_category if __name__ == '__main__': records_maincategory, records_category = read_category_instance() model = 'dasa.hartakaruncategory' out_fn = 'fixtures/hartakaruncategory.json' out_fn = os.path.abspath(out_fn) create_fixture(model=model, data=records_category, out_fn=out_fn) load_fixture(out_fn, model=model) model = 'dasa.hartakarunmaincategory' out_fn = 'fixtures/hartakarunmaincategory.json' out_fn = os.path.abspath(out_fn) create_fixture(model=model, data=records_maincategory, out_fn=out_fn) load_fixture(out_fn, model=model)
with patch("fah.pfreeathome.Client.__init__", return_value=None): yield @pytest.fixture(autouse=True) def mock_roomnames(): with patch("fah.pfreeathome.get_room_names", return_value={"00": { "00": "room1", "01": "room2" }}): yield @patch("fah.pfreeathome.Client.get_config", return_value=load_fixture("1004_room_temperature_controller.xml")) class TestClimate: async def test_climate(self, _): client = get_client() await client.find_devices(True) devices = client.get_devices("thermostat") assert len(devices) == 1 climate = next( (el for el in devices if el.lookup_key == "ABB700D12345/ch0000")) # Test attributes assert climate.name == "RTR AB (room1)" assert climate.serialnumber == "ABB700D12345" assert climate.channel_id == "ch0000" assert climate.device_info["identifiers"] == {("freeathome",
client.monitored_datapoints = {} client.set_datapoint = AsyncMock() return client @pytest.fixture(autouse=True) def mock_init(): with patch("fah.pfreeathome.Client.__init__", return_value=None): yield @pytest.fixture(autouse=True) def mock_roomnames(): with patch("fah.pfreeathome.get_room_names", return_value={"00":{"00":"room1", "01":"room2"}}): yield @patch("fah.pfreeathome.Client.get_config", return_value=load_fixture("100C_sensor_actuator_1gang.xml")) class TestLight: async def test_light(self, _): client = get_client() await client.find_devices(True) devices = client.get_devices("light") assert len(devices) == 1 light = next((el for el in devices if el.lookup_key == "ABB700D12345/ch0003")) # Test attributes assert light.name == "Büro (room1)" assert light.serialnumber == "ABB700D12345" assert light.channel_id == "ch0003" assert light.device_info["identifiers"] == {("freeathome", "ABB700D12345")} assert light.device_info["name"] == "Sensor/ Schaltaktor Büro (ABB700D12345)"
async def test_cover(self, _): client = get_client() await client.find_devices(True) devices = client.get_devices("cover") assert len(client.get_devices("cover")) == 1 cover = next( (el for el in devices if el.lookup_key == "ABB700D12345/ch0003")) # Test attributes assert cover.name == "Gäste-WC (room1)" assert cover.serialnumber == "ABB700D12345" assert cover.channel_id == "ch0003" assert cover.device_info["identifiers"] == {("freeathome", "ABB700D12345")} assert cover.device_info[ "name"] == "Sensor/ Jalousieaktor 1/1-fach (ABB700D12345)" assert cover.device_info["model"] == "Sensor/ Jalousieaktor 1/1-fach" assert cover.device_info["sw_version"] == "2.1366" # TODO: Convert to int, make this a getter # TODO: This should return 73, reverse values in component assert cover.position == "27" assert cover.get_forced_cover_position() == "none" assert cover.state == "1" assert cover.is_cover_closed() == False assert cover.is_cover_opening() == False assert cover.is_cover_closing() == False # Test datapoints await cover.open_cover() client.set_datapoint.assert_called_once_with("ABB700D12345", "ch0003", "idp0000", "0") client.set_datapoint.reset_mock() await cover.close_cover() client.set_datapoint.assert_called_once_with("ABB700D12345", "ch0003", "idp0000", "1") client.set_datapoint.reset_mock() # Simulate cover moving cover.state = '2' await cover.stop_cover() client.set_datapoint.assert_called_once_with("ABB700D12345", "ch0003", "idp0001", "1") client.set_datapoint.reset_mock() await cover.set_cover_position(41) # TODO: This should set 41, reverse in component client.set_datapoint.assert_called_once_with("ABB700D12345", "ch0003", "idp0002", "59") client.set_datapoint.reset_mock() await cover.set_forced_cover_position("none") client.set_datapoint.assert_called_once_with("ABB700D12345", "ch0003", "idp0004", "1") # Status updates await client.update_devices(load_fixture("1013_update_closing.xml")) assert cover.is_cover_opening() == False assert cover.is_cover_closing() == True await client.update_devices(load_fixture("1013_update_closed.xml")) assert cover.is_cover_opening() == False assert cover.is_cover_closing() == False assert cover.is_cover_closed() == True # TODO: This should return 100, reverse values in component assert cover.position == "0" await client.update_devices(load_fixture("1013_update_opening.xml")) assert cover.is_cover_opening() == True assert cover.is_cover_closing() == False await client.update_devices(load_fixture("1013_update_open.xml")) assert cover.is_cover_opening() == False assert cover.is_cover_closing() == False assert cover.is_cover_closed() == False # TODO: This should return 64, reverse values in component assert cover.position == "36" await client.update_devices( load_fixture("1013_update_force_opening.xml")) assert cover.is_cover_opening() == True assert cover.is_cover_closing() == False assert cover.is_cover_closed() == False assert cover.get_forced_cover_position() == "open" await client.update_devices( load_fixture("1013_update_force_open_disabled.xml")) assert cover.is_cover_opening() == False assert cover.is_cover_closing() == True assert cover.is_cover_closed() == False assert cover.get_forced_cover_position() == "none"
async def test_cover_without_set_position(self, _): client = get_client() await client.find_devices(False) devices = client.get_devices("cover") assert len(client.get_devices("cover")) == 1 cover = next( (el for el in devices if el.lookup_key == "ABB5000ABCDE/ch0000")) # Test attributes assert cover.name == "Cover" assert cover.serialnumber == "ABB5000ABCDE" assert cover.channel_id == "ch0000" assert cover.device_info["identifiers"] == {("freeathome", "ABB5000ABCDE")} assert cover.device_info["name"] == "2CSYE1105 (ABB5000ABCDE)" assert cover.device_info["model"] == "2CSYE1105" assert cover.device_info["sw_version"] == "1.51" assert cover.position == None assert cover.forced_position == None assert cover.state == "1" assert cover.is_cover_closed() == None assert cover.is_cover_opening() == False assert cover.is_cover_closing() == False # Test datapoints await cover.open_cover() client.set_datapoint.assert_called_once_with("ABB5000ABCDE", "ch0000", "idp0000", "0") client.set_datapoint.reset_mock() await cover.close_cover() client.set_datapoint.assert_called_once_with("ABB5000ABCDE", "ch0000", "idp0000", "1") client.set_datapoint.reset_mock() # Simulate cover moving cover.state = '2' await cover.stop_cover() client.set_datapoint.assert_called_once_with("ABB5000ABCDE", "ch0000", "idp0001", "1") # Status updates await client.update_devices(load_fixture("0109_update_closing.xml")) assert cover.is_cover_opening() == False assert cover.is_cover_closing() == True assert cover.is_cover_closed() == None await client.update_devices(load_fixture("0109_update_closed.xml")) assert cover.is_cover_opening() == False assert cover.is_cover_closing() == False assert cover.is_cover_closed() == None await client.update_devices(load_fixture("0109_update_opening.xml")) assert cover.is_cover_opening() == True assert cover.is_cover_closing() == False assert cover.is_cover_closed() == None await client.update_devices(load_fixture("0109_update_open.xml")) assert cover.is_cover_opening() == False assert cover.is_cover_closing() == False assert cover.is_cover_closed() == None
client.monitored_datapoints = {} client.set_datapoint = AsyncMock() return client @pytest.fixture(autouse=True) def mock_init(): with patch("fah.pfreeathome.Client.__init__", return_value=None): yield @pytest.fixture(autouse=True) def mock_roomnames(): with patch("fah.pfreeathome.get_room_names", return_value={"00":{"00":"room1", "01":"room2"}}): yield @patch("fah.pfreeathome.Client.get_config", return_value=load_fixture("unknown_panel.xml")) class TestLock: async def test_lock(self, _): client = get_client() await client.find_devices(True) assert len(client.get_devices("light")) == 0 devices = client.get_devices("lock") assert len(devices) == 1 lock = next((el for el in devices if el.lookup_key == "ABB654612345/ch0010")) # Test attributes assert lock.name == "Door opener (room1)" assert lock.serialnumber == "ABB654612345" assert lock.channel_id == "ch0010"
def load_items(): data = read_items() out_fn = os.path.abspath(OUT_FN) create_fixture(model=MODEL, data=data, out_fn=out_fn) load_fixture(out_fn)
def load_items(): data = read_items() create_fixture(model=MODEL, data=data, out_fn=out_fn) load_fixture(out_fn)
async def test_climate(self, _): client = get_client() await client.find_devices(True) devices = client.get_devices("thermostat") assert len(devices) == 1 climate = next( (el for el in devices if el.lookup_key == "ABB700D12345/ch0000")) # Test attributes assert climate.name == "RTR AB (room1)" assert climate.serialnumber == "ABB700D12345" assert climate.channel_id == "ch0000" assert climate.device_info["identifiers"] == {("freeathome", "ABB700D12345")} assert climate.device_info["name"] == "RTR AB (ABB700D12345)" assert climate.device_info["model"] == "Raumtemperaturregler" assert climate.device_info["sw_version"] == "2.1139" # TODO: Convert to decimal # TODO: This should be its own sensor assert climate.current_temperature == '21.56' assert climate.target_temperature == '20' # TODO: This should be its own sensor assert climate.current_actuator == '16' assert climate.state == True assert climate.ecomode == False # Test datapoints await climate.turn_on() client.set_datapoint.assert_has_calls([ call("ABB700D12345", "ch0000", "idp0011", "0"), call("ABB700D12345", "ch0000", "idp0012", "1"), ]) client.set_datapoint.reset_mock() await climate.turn_off() client.set_datapoint.assert_called_once_with("ABB700D12345", "ch0000", "idp0012", "0") client.set_datapoint.reset_mock() await climate.eco_mode() client.set_datapoint.assert_called_once_with("ABB700D12345", "ch0000", "idp0011", "1") client.set_datapoint.reset_mock() await climate.set_target_temperature(22.5) client.set_datapoint.assert_called_once_with("ABB700D12345", "ch0000", "idp0016", "22.50") # Test changing target temperature await client.update_devices( load_fixture("1004_update_target_temperature.xml")) assert climate.target_temperature == '20.5' # Test updating current temperature await client.update_devices( load_fixture("1004_update_current_temperature.xml")) assert climate.current_temperature == '20.9' # Test eco mode turned on await client.update_devices(load_fixture("1004_update_eco_mode.xml")) assert climate.ecomode == True # Test device turned off await client.update_devices(load_fixture("1004_update_turn_off.xml")) assert climate.state == False # Test device turned back on, target temperature, and actuator value up await client.update_devices(load_fixture("1004_update_turn_on.xml")) assert climate.state == True assert climate.target_temperature == '18' assert climate.current_actuator == '27' # Test eco mode turned off, and target temperature up await client.update_devices( load_fixture("1004_update_eco_mode_off.xml")) assert climate.ecomode == False assert climate.target_temperature == '21' # Test alternative ecomode turn on climate.update_datapoint('odp0009', '36') assert climate.ecomode == True climate.update_datapoint('odp0009', '33') assert climate.ecomode == False
client.monitored_datapoints = {} client.set_datapoint = AsyncMock() return client @pytest.fixture(autouse=True) def mock_init(): with patch("fah.pfreeathome.Client.__init__", return_value=None): yield @pytest.fixture(autouse=True) def mock_roomnames(): with patch("fah.pfreeathome.get_room_names", return_value={"00":{"00":"room1", "01":"room2"}}): yield @patch("fah.pfreeathome.Client.get_config", return_value=load_fixture("100A_movement_detector_actuator_1gang.xml")) class TestMovementDetectorLuxSensor: async def get_client(self): client = Client() client.devices = set() client.set_datapoint = AsyncMock() return client async def test_movement_detector_lux_sensor(self, _): client = await self.get_client() await client.find_devices(True) sensor_devices = client.get_devices("sensor") assert len(sensor_devices) == 1