-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from grimmpp/feature-branch
better tests added for binary sensors
- Loading branch information
Showing
14 changed files
with
373 additions
and
162 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
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 was deleted.
Oops, something went wrong.
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,33 @@ | ||
import unittest | ||
from mocks import * | ||
from unittest import mock | ||
from homeassistant.helpers.entity import Entity | ||
from homeassistant.const import Platform | ||
from custom_components.eltako.binary_sensor import EltakoBinarySensor | ||
from custom_components.eltako.config_helpers import * | ||
from eltakobus import * | ||
from eltakobus.eep import * | ||
|
||
from tests.test_binary_sensor_generic import TestBinarySensor | ||
|
||
# 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 TestBinarySensor_A5_07_01(unittest.TestCase): | ||
|
||
def test_occupancy_sensor(self): | ||
bs = TestBinarySensor().create_binary_sensor(eep_string="A5-07-01") | ||
|
||
self.assertEqual(bs._attr_is_on, None) | ||
|
||
msg = Regular4BSMessage(address=b'\x00\x00\x10\x08', data=b'\x00\x96\xC8\x09', status=b'\x00') | ||
|
||
bs.value_changed(msg) | ||
self.assertEqual(bs._attr_is_on, True) | ||
|
||
msg.data = b'\x00\x96\x0A\x09' | ||
bs.value_changed(msg) | ||
self.assertEqual(bs._attr_is_on, False) | ||
|
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,20 @@ | ||
import unittest | ||
from mocks import * | ||
from unittest import mock | ||
from homeassistant.helpers.entity import Entity | ||
from homeassistant.const import Platform | ||
from custom_components.eltako.binary_sensor import EltakoBinarySensor | ||
from custom_components.eltako.config_helpers import * | ||
from eltakobus import * | ||
from eltakobus.eep import * | ||
|
||
from tests.test_binary_sensor_generic import TestBinarySensor | ||
|
||
# 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 TestBinarySensor_A5_08_01(unittest.TestCase): | ||
"""Test missing""" | ||
|
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,53 @@ | ||
import unittest | ||
from mocks import * | ||
from unittest import mock | ||
from homeassistant.helpers.entity import Entity | ||
from homeassistant.const import Platform | ||
from custom_components.eltako.binary_sensor import EltakoBinarySensor | ||
from custom_components.eltako.config_helpers import * | ||
from eltakobus import * | ||
from eltakobus.eep import * | ||
|
||
from tests.test_binary_sensor_generic import TestBinarySensor | ||
|
||
# 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 TestBinarySensor_D5_00_01(unittest.TestCase): | ||
|
||
def test_binary_sensor_window_contact_triggered_via_FTS14EM(self): | ||
bs = TestBinarySensor().create_binary_sensor(eep_string="D5-00-01", device_class = "window", invert_signal = False) | ||
|
||
# test if sensor object is newly created | ||
self.assertEqual(bs._attr_is_on, None) | ||
|
||
# test if state is set to no contact | ||
bs._attr_is_on = False | ||
self.assertEqual(bs._attr_is_on, False) | ||
|
||
msg = Regular1BSMessage(address=b'\x00\x00\x10\x08', | ||
data=b'\x09', #open | ||
status=b'\x00') | ||
|
||
# test if signal is processed correctly (switch on) | ||
bs.value_changed(msg) | ||
self.assertEqual(bs._attr_is_on, False) | ||
|
||
# test if signal is processed correctly (switch on) | ||
bs.invert_signal = True | ||
bs.value_changed(msg) | ||
self.assertEqual(bs._attr_is_on, True) | ||
|
||
# test if signal is processed correctly (switch off) | ||
msg.data = b'\x08' # closed | ||
bs.invert_signal = False | ||
bs.value_changed(msg) | ||
self.assertEqual(bs._attr_is_on, True) | ||
|
||
# test if signal is processed correctly (switch off) | ||
bs.invert_signal = True | ||
bs.value_changed(msg) | ||
self.assertEqual(bs._attr_is_on, False) | ||
|
Oops, something went wrong.