Skip to content

Commit

Permalink
tests added and improved
Browse files Browse the repository at this point in the history
  • Loading branch information
grimmpp committed Mar 26, 2024
1 parent 79a0703 commit 8e71d6d
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions eltakodevice_discovery/readme.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
46 changes: 46 additions & 0 deletions tests/test_sensor_A5_04_01.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions tests/test_sensor_A5_04_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down
50 changes: 50 additions & 0 deletions tests/test_sensor_A5_10_06.py
Original file line number Diff line number Diff line change
@@ -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)
68 changes: 68 additions & 0 deletions tests/test_sensor_A5_10_12.py
Original file line number Diff line number Diff line change
@@ -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)
30 changes: 0 additions & 30 deletions tests/test_sensor.py → tests/test_sensor_A5_13_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
48 changes: 48 additions & 0 deletions tests/test_sensor_F6_10_00.py
Original file line number Diff line number Diff line change
@@ -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')

0 comments on commit 8e71d6d

Please sign in to comment.