Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [feature] Add support for Translator sensor #111

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/qolsysgw/mqtt/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from qolsys.sensors import QolsysSensorTakeoverModule
from qolsys.sensors import QolsysSensorTemperature
from qolsys.sensors import QolsysSensorTilt
from qolsys.sensors import QolsysSensorTranslator
from qolsys.sensors import QolsysSensorWater
from qolsys.sensors import _QolsysSensorWithoutUpdates
from qolsys.state import QolsysState
Expand Down Expand Up @@ -448,6 +449,7 @@ class MqttWrapperQolsysSensor(MqttWrapper):
QolsysSensorKeyFob: 'safety',
QolsysSensorTemperature: 'heat',
QolsysSensorTakeoverModule: 'safety',
QolsysSensorTranslator: 'safety',
}

def __init__(self, sensor: QolsysSensor, *args, **kwargs):
Expand Down
6 changes: 6 additions & 0 deletions apps/qolsysgw/qolsys/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,9 @@ class QolsysSensorTakeoverModule(QolsysSensor, _QolsysSensorWithoutUpdates):
@classmethod
def from_json(cls, data, common=None):
return cls.from_json_subclass('TakeoverModule', data, common)


class QolsysSensorTranslator(QolsysSensor, _QolsysSensorWithoutUpdates):
@classmethod
def from_json(cls, data, common=None):
return cls.from_json_subclass('Translator', data, common)
28 changes: 27 additions & 1 deletion tests/end-to-end/test_qolsysgw.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,19 @@ async def _check_initial_state(self, ctx):
'entity_id': 'binary_sensor.my_takeovermodule_sensor',
'state': 'off',
},
{
'attributes': {
'device_class': 'safety',
'friendly_name': 'My Translator Sensor',
'group': 'translator',
'zone_alarm_type': 0,
'zone_physical_type': 14,
'zone_type': 20,
'tampered': False,
},
'entity_id': 'binary_sensor.my_translator_sensor',
'state': 'off',
},
]
self._check_entity_states(ctx, expected_states, msg='Initial state')

Expand All @@ -525,7 +538,7 @@ async def _check_panel_events(self, ctx):

closed_entities = [100, 110, 111, 120, 121, 130, 140, 141, 150,
200, 210, 220, 221, 230, 240, 250, 260, 270,
280]
280, 281]
open_entities = [101]
tamper_entities = [100, 110, 111, 210]
untamper_entities_to_open = [100]
Expand Down Expand Up @@ -910,6 +923,19 @@ def zone_active_event(zone_id, closed=False):
'entity_id': 'binary_sensor.my_takeovermodule_sensor',
'state': 'on',
},
{
'attributes': {
'device_class': 'safety',
'friendly_name': 'My Translator Sensor',
'group': 'translator',
'zone_alarm_type': 0,
'zone_physical_type': 14,
'zone_type': 20,
'tampered': False,
},
'entity_id': 'binary_sensor.my_translator_sensor',
'state': 'on',
},
]
self._check_entity_states(ctx, expected_states, msg='Panel events')

Expand Down
28 changes: 26 additions & 2 deletions tests/integration/test_qolsys_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
from qolsys.sensors import QolsysSensorPanelMotion
from qolsys.sensors import QolsysSensorSiren
from qolsys.sensors import QolsysSensorSmokeDetector
from qolsys.sensors import QolsysSensorTemperature
from qolsys.sensors import QolsysSensorTakeoverModule
from qolsys.sensors import QolsysSensorTemperature
from qolsys.sensors import QolsysSensorTilt
from qolsys.sensors import QolsysSensorTranslator
from qolsys.sensors import QolsysSensorWater


Expand Down Expand Up @@ -259,7 +260,7 @@ async def test_integration_event_info_summary_initializes_all_entities(self):

with self.subTest(msg='Partition 1 is properly configured'):
partition1 = state.partition(1)
self.assertEqual(10, len(partition1.sensors))
self.assertEqual(11, len(partition1.sensors))
self.assertEqual(1, partition1.id)
self.assertEqual('partition1', partition1.name)
self.assertEqual('DISARM', partition1.status)
Expand Down Expand Up @@ -734,6 +735,29 @@ async def test_integration_event_info_summary_initializes_all_entities(self):
expected_enabled_by_default=False,
)

with self.subTest(msg='Sensor 281 is properly configured'):
sensor281 = partition1.zone(281)
self.assertEqual(QolsysSensorTranslator, sensor281.__class__)
self.assertEqual('002-0081', sensor281.id)
self.assertEqual('My Translator Sensor', sensor281.name)
self.assertEqual('translator', sensor281.group)
self.assertEqual('Closed', sensor281.status)
self.assertEqual('0', sensor281.state)
self.assertEqual(281, sensor281.zone_id)
self.assertEqual(14, sensor281.zone_physical_type)
self.assertEqual(0, sensor281.zone_alarm_type)
self.assertEqual(20, sensor281.zone_type)
self.assertEqual(1, sensor281.partition_id)

await self._check_sensor_mqtt_messages(
gw=gw,
sensor_flat_name='my_translator_sensor',
sensor_unique_id='002_0081',
sensor_state=sensor281,
expected_device_class='safety',
expected_enabled_by_default=False,
)

async def _test_integration_event_info_secure_arm(self, from_secure_arm,
to_secure_arm):
panel, gw, _, _ = await self._ready_panel_and_gw(
Expand Down
13 changes: 13 additions & 0 deletions tests/mock_modules/testutils/fixtures_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,19 @@ def get_summary(secure_arm=False, partition_ids=None,
'zone_type': 18,
'partition_id': 1,
},
{
'id': '002-0081',
'type': 'Translator',
'name': 'My Translator Sensor',
'group': 'translator',
'status': 'Closed',
'state': '0',
'zone_id': 281,
'zone_physical_type': 14,
'zone_alarm_type': 0,
'zone_type': 20,
'partition_id': 1,
},
],
},
],
Expand Down