diff --git a/README.md b/README.md index 68162f20..8a0e6325 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Elatko devices are exemplarily mentioned. You can find [here](https://www.eltako * Binary sensor * F6-02-01 ([Rocker switch](https://github.com/grimmpp/home-assistant-eltako/tree/main/docs/rocker_switch/readme.md), FTS14EM) * F6-02-02 ([Rocker switch](https://github.com/grimmpp/home-assistant-eltako/tree/main/docs/rocker_switch/readme.md)) - * F6-10-00 (Window handle, FTS14EM) + * F6-10-00 (Window handle, classic switches or contacs via FTS14EM, window and door contacts like FTKE) * D5-00-01 ([Contact sensor](https://github.com/grimmpp/home-assistant-eltako/tree/main//docs/window_sensor_setup_FTS14EM.md), FTS14EM) incl. signal inverter * A5-07-01 (Occupancy sensor) * Sensor diff --git a/changes.md b/changes.md index 12056805..dd2977d7 100644 --- a/changes.md +++ b/changes.md @@ -4,6 +4,7 @@ * Added Service for sending arbritrary ESP2 messages * 🐞 Fix for TargetTemperatureSensor (EEP: A5-10-06 and A5-10-12) * 🐞 Fix for unknow cover positions. +* Unit-Tests added and improved for EEP A5-04-01, A5-04-02, A5-10-06, A5-10-12, A5-13-01, and F6-10-00. ## Version 1.4.0 ESP3 Support (USB300) * Docs about gateway usage added. diff --git a/eltakodevice_discovery/readme.md b/eltakodevice_discovery/readme.md index 6c606d0a..dbd61607 100644 --- a/eltakodevice_discovery/readme.md +++ b/eltakodevice_discovery/readme.md @@ -1,5 +1,7 @@ # Eltako Device and Sensor Discovery +# DEPRECATED: Check out [EnOnocean Device Manager](https://github.com/grimmpp/enocean-device-manager) + Main purpose of this tool is to programmatically prepare the Home Assistance configuration as good as possible. ## Limitation diff --git a/tests/test_sensor_A5_04_01.py b/tests/test_sensor_A5_04_01.py new file mode 100644 index 00000000..633f910e --- /dev/null +++ b/tests/test_sensor_A5_04_01.py @@ -0,0 +1,46 @@ +import unittest +from custom_components.eltako.sensor import * +from mocks import HassMock +from unittest import mock +from mocks import * +from homeassistant.helpers.entity import Entity +from homeassistant.const import Platform +from custom_components.eltako.binary_sensor import EltakoBinarySensor +from eltakobus import * + +# mock update of Home Assistant +Entity.schedule_update_ha_state = mock.Mock(return_value=None) +# EltakoBinarySensor.hass.bus.fire is mocked by class HassMock + + +class TestSensor_A5_04_01(unittest.TestCase): + + msg1 = Regular4BSMessage (address=b'\xFF\xFF\x00\x80', data=b'\xaa\x00\x00\x0d', status=0x00) + + def create_temperature_sensor(self) -> EltakoTemperatureSensor: + gateway = GatewayMock() + dev_id = AddressExpression.parse("FF-FF-00-80") + dev_name = "device name" + dev_eep = EEP.find("A5-04-01") + s = EltakoTemperatureSensor(Platform.SENSOR, gateway, dev_id, dev_name, dev_eep) + return s + + def create_humidity_sensor(self) -> EltakoHumiditySensor: + gateway = GatewayMock() + dev_id = AddressExpression.parse("FF-FF-00-80") + dev_name = "device name" + dev_eep = EEP.find("A5-04-01") + s = EltakoHumiditySensor(Platform.SENSOR, gateway, dev_id, dev_name, dev_eep) + return s + + def test_temperature_sensor_A5_04_02(self): + s_temp = self.create_temperature_sensor() + + s_temp.value_changed(self.msg1) + self.assertEqual(s_temp.native_value, 0.0) + + def test_humidity_sensor_A5_04_02(self): + s_hum = self.create_humidity_sensor() + + s_hum.value_changed(self.msg1) + self.assertEqual(s_hum.native_value, 0.0) \ No newline at end of file diff --git a/tests/test_sensor_A5_04_02.py b/tests/test_sensor_A5_04_02.py index cf48608e..0cc15375 100644 --- a/tests/test_sensor_A5_04_02.py +++ b/tests/test_sensor_A5_04_02.py @@ -21,7 +21,7 @@ def create_temperature_sensor(self) -> EltakoTemperatureSensor: gateway = GatewayMock() dev_id = AddressExpression.parse("FF-FF-00-80") dev_name = "device name" - dev_eep = EEP.find("A5-08-01") + dev_eep = EEP.find("A5-04-02") s = EltakoTemperatureSensor(Platform.SENSOR, gateway, dev_id, dev_name, dev_eep) return s @@ -37,7 +37,7 @@ def test_temperature_sensor_A5_04_02(self): s_temp = self.create_temperature_sensor() s_temp.value_changed(self.msg1) - self.assertEqual(s_temp.native_value, 0.0) + self.assertEqual(s_temp.native_value, -20.0) def test_humidity_sensor_A5_04_02(self): s_hum = self.create_humidity_sensor() diff --git a/tests/test_sensor_A5_10_06.py b/tests/test_sensor_A5_10_06.py new file mode 100644 index 00000000..20194ffe --- /dev/null +++ b/tests/test_sensor_A5_10_06.py @@ -0,0 +1,50 @@ +import unittest +from custom_components.eltako.sensor import * +from mocks import HassMock +from unittest import mock +from mocks import * +from homeassistant.helpers.entity import Entity +from homeassistant.const import Platform +from custom_components.eltako.binary_sensor import EltakoBinarySensor +from eltakobus import * + +# mock update of Home Assistant +Entity.schedule_update_ha_state = mock.Mock(return_value=None) +# EltakoBinarySensor.hass.bus.fire is mocked by class HassMock + + +class TestSensor_A5_10_06(unittest.TestCase): + + msg = Regular4BSMessage (address=b'\xFF\xFF\x00\x80', data=b'\xaa\x80\x76\x0f', status=0x00) + + def create_temp_sensor(self) -> EltakoTemperatureSensor: + gateway = GatewayMock() + dev_id = AddressExpression.parse("FF-FF-00-80") + dev_name = "device name" + dev_eep = EEP.find("A5-10-06") + s = EltakoTemperatureSensor(Platform.SENSOR, gateway, dev_id, dev_name, dev_eep) + return s + + def create_target_temp_sensor(self) -> EltakoTargetTemperatureSensor: + gateway = GatewayMock() + dev_id = AddressExpression.parse("FF-FF-00-80") + dev_name = "device name" + dev_eep = EEP.find("A5-10-06") + s = EltakoTargetTemperatureSensor(Platform.SENSOR, gateway, dev_id, dev_name, dev_eep) + return s + + def test_temp_sensor(self): + ts = self.create_temp_sensor() + + self.assertEqual(ts.native_value, None) + ts.value_changed(self.msg) + + self.assertEqual(ts.native_value, 21.49019607843137) + + def test_target_temp_sensor(self): + ts = self.create_target_temp_sensor() + + self.assertEqual(ts.native_value, None) + ts.value_changed(self.msg) + + self.assertEqual(ts.native_value, 20) \ No newline at end of file diff --git a/tests/test_sensor_A5_10_12.py b/tests/test_sensor_A5_10_12.py new file mode 100644 index 00000000..47a68901 --- /dev/null +++ b/tests/test_sensor_A5_10_12.py @@ -0,0 +1,68 @@ +import unittest +from custom_components.eltako.sensor import * +from mocks import HassMock +from unittest import mock +from mocks import * +from homeassistant.helpers.entity import Entity +from homeassistant.const import Platform +from custom_components.eltako.binary_sensor import EltakoBinarySensor +from eltakobus import * + +# mock update of Home Assistant +Entity.schedule_update_ha_state = mock.Mock(return_value=None) +# EltakoBinarySensor.hass.bus.fire is mocked by class HassMock + + +class TestSensor_A5_10_12(unittest.TestCase): + + msg = Regular4BSMessage (address=b'\xFF\xFF\x00\x80', data=b'\xaa\x80\x76\x0f', status=0x00) + + def create_temp_sensor(self) -> EltakoTemperatureSensor: + gateway = GatewayMock() + dev_id = AddressExpression.parse("FF-FF-00-80") + dev_name = "device name" + dev_eep = EEP.find("A5-10-12") + s = EltakoTemperatureSensor(Platform.SENSOR, gateway, dev_id, dev_name, dev_eep) + return s + + def create_target_temp_sensor(self) -> EltakoTargetTemperatureSensor: + gateway = GatewayMock() + dev_id = AddressExpression.parse("FF-FF-00-80") + dev_name = "device name" + dev_eep = EEP.find("A5-10-12") + s = EltakoTargetTemperatureSensor(Platform.SENSOR, gateway, dev_id, dev_name, dev_eep) + return s + + def create_humidity_sensor(self) -> EltakoHumiditySensor: + gateway = GatewayMock() + dev_id = AddressExpression.parse("FF-FF-00-80") + dev_name = "device name" + dev_eep = EEP.find("A5-10-12") + s = EltakoHumiditySensor(Platform.SENSOR, gateway, dev_id, dev_name, dev_eep) + return s + + + def test_temp_sensor(self): + ts = self.create_temp_sensor() + + self.assertEqual(ts.native_value, None) + ts.value_changed(self.msg) + + self.assertEqual(ts.native_value, 18.88) + + + def test_target_temp_sensor(self): + ts = self.create_target_temp_sensor() + + self.assertEqual(ts.native_value, None) + ts.value_changed(self.msg) + + self.assertEqual(ts.native_value, 27) + + def test_humidity_sensor(self): + hs = self.create_humidity_sensor() + + self.assertEqual(hs.native_value, None) + hs.value_changed(self.msg) + + self.assertEqual(hs.native_value, 51.2) \ No newline at end of file diff --git a/tests/test_sensor.py b/tests/test_sensor_A5_13_01.py similarity index 67% rename from tests/test_sensor.py rename to tests/test_sensor_A5_13_01.py index 45d64cd0..5efcd185 100644 --- a/tests/test_sensor.py +++ b/tests/test_sensor_A5_13_01.py @@ -24,14 +24,6 @@ def create_weatherstation_sensor(self, description: EltakoSensorEntityDescriptio return ews - def create_window_handle_sensor(self) -> EltakoWindowHandle: - gateway = GatewayMock() - dev_id = AddressExpression.parse("51-E8-00-01") - dev_name = "dev name" - dev_eep = EEP.find("F6-10-00") - ews = EltakoWindowHandle(Platform.SENSOR, gateway, dev_id, dev_name, dev_eep, SENSOR_DESC_WINDOWHANDLE) - - return ews def test_weatherstation_sensor(self): ews = self.create_weatherstation_sensor(SENSOR_DESC_WEATHER_STATION_ILLUMINANCE_DAWN) @@ -75,25 +67,3 @@ def test_weatherstation_sensor(self): ews.value_changed(msg) self.assertEqual(ews.native_value, 588.2352941176471) - - def test_window_handle(self): - whs = self.create_window_handle_sensor() - - whs.entity_description = SENSOR_DESC_WINDOWHANDLE - whs._attr_native_value = -1 - - msg = RPSMessage(address=b'\x05\x1e\x83\x15', status=b'\x20', data=b'\xF0', outgoing=False) - whs.value_changed(msg) - self.assertEqual(whs._attr_native_value, STATE_CLOSED) - - msg = RPSMessage(address=b'\x05\x1e\x83\x15', status=b'\x20', data=b'\xC0', outgoing=False) - whs.value_changed(msg) - self.assertEqual(whs._attr_native_value, STATE_OPEN) - - msg = RPSMessage(address=b'\x05\x1e\x83\x15', status=b'\x20', data=b'\xE0', outgoing=False) - whs.value_changed(msg) - self.assertEqual(whs._attr_native_value, STATE_OPEN) - - msg = RPSMessage(address=b'\x05\x1e\x83\x15', status=b'\x20', data=b'\xD0', outgoing=False) - whs.value_changed(msg) - self.assertEqual(whs._attr_native_value, 'tilt') \ No newline at end of file diff --git a/tests/test_sensor_F6_10_00.py b/tests/test_sensor_F6_10_00.py new file mode 100644 index 00000000..f8750e38 --- /dev/null +++ b/tests/test_sensor_F6_10_00.py @@ -0,0 +1,48 @@ +import unittest +from custom_components.eltako.sensor import * +from mocks import HassMock +from unittest import mock +from mocks import * +from homeassistant.helpers.entity import Entity +from homeassistant.const import Platform +from custom_components.eltako.binary_sensor import EltakoBinarySensor +from eltakobus import * + +# mock update of Home Assistant +Entity.schedule_update_ha_state = mock.Mock(return_value=None) +# EltakoBinarySensor.hass.bus.fire is mocked by class HassMock + + +class TestSensor(unittest.TestCase): + + def create_window_handle_sensor(self) -> EltakoWindowHandle: + gateway = GatewayMock() + dev_id = AddressExpression.parse("51-E8-00-01") + dev_name = "dev name" + dev_eep = EEP.find("F6-10-00") + ews = EltakoWindowHandle(Platform.SENSOR, gateway, dev_id, dev_name, dev_eep, SENSOR_DESC_WINDOWHANDLE) + + return ews + + + def test_window_handle(self): + whs = self.create_window_handle_sensor() + + whs.entity_description = SENSOR_DESC_WINDOWHANDLE + whs._attr_native_value = -1 + + msg = RPSMessage(address=b'\x05\x1e\x83\x15', status=b'\x20', data=b'\xF0', outgoing=False) + whs.value_changed(msg) + self.assertEqual(whs._attr_native_value, STATE_CLOSED) + + msg = RPSMessage(address=b'\x05\x1e\x83\x15', status=b'\x20', data=b'\xC0', outgoing=False) + whs.value_changed(msg) + self.assertEqual(whs._attr_native_value, STATE_OPEN) + + msg = RPSMessage(address=b'\x05\x1e\x83\x15', status=b'\x20', data=b'\xE0', outgoing=False) + whs.value_changed(msg) + self.assertEqual(whs._attr_native_value, STATE_OPEN) + + msg = RPSMessage(address=b'\x05\x1e\x83\x15', status=b'\x20', data=b'\xD0', outgoing=False) + whs.value_changed(msg) + self.assertEqual(whs._attr_native_value, 'tilt') \ No newline at end of file