-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
218 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |