Skip to content

Commit

Permalink
✨ [feature] Add support for KeyFob sensors (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
xaf authored Feb 19, 2023
1 parent 8e744c4 commit 0da482e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apps/qolsysgw/mqtt/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from qolsys.sensors import QolsysSensorFreeze
from qolsys.sensors import QolsysSensorGlassBreak
from qolsys.sensors import QolsysSensorHeat
from qolsys.sensors import QolsysSensorKeyFob
from qolsys.sensors import QolsysSensorKeypad
from qolsys.sensors import QolsysSensorMotion
from qolsys.sensors import QolsysSensorSiren
Expand Down Expand Up @@ -442,6 +443,7 @@ class MqttWrapperQolsysSensor(MqttWrapper):
QolsysSensorKeypad: 'safety',
QolsysSensorAuxiliaryPendant: 'safety',
QolsysSensorSiren: 'safety',
QolsysSensorKeyFob: '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 @@ -320,3 +320,9 @@ class QolsysSensorSiren(QolsysSensor, _QolsysSensorWithoutUpdates):
@classmethod
def from_json(cls, data, common=None):
return cls.from_json_subclass('Siren', data, common)


class QolsysSensorKeyFob(QolsysSensor, _QolsysSensorWithoutUpdates):
@classmethod
def from_json(cls, data, common=None):
return cls.from_json_subclass('KeyFob', 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 @@ -464,6 +464,19 @@ async def _check_initial_state(self, ctx):
'entity_id': 'binary_sensor.my_siren_sensor',
'state': 'off',
},
{
'attributes': {
'device_class': 'safety',
'friendly_name': 'My KeyFob Sensor',
'group': 'mobileintrusion',
'zone_alarm_type': 0,
'zone_physical_type': 3,
'zone_type': 102,
'tampered': False,
},
'entity_id': 'binary_sensor.my_keyfob_sensor',
'state': 'off',
},
]
self._check_entity_states(ctx, expected_states, msg='Initial state')

Expand All @@ -485,7 +498,7 @@ async def _check_panel_events(self, ctx):
]

closed_entities = [100, 110, 111, 120, 121, 130, 140, 141, 150,
200, 210, 220, 230, 240, 250, 260]
200, 210, 220, 230, 240, 250, 260, 270]
open_entities = [101]
tamper_entities = [100, 110, 111, 210]
untamper_entities_to_open = [100]
Expand Down Expand Up @@ -831,6 +844,19 @@ def zone_active_event(zone_id, closed=False):
'entity_id': 'binary_sensor.my_siren_sensor',
'state': 'on',
},
{
'attributes': {
'device_class': 'safety',
'friendly_name': 'My KeyFob Sensor',
'group': 'mobileintrusion',
'zone_alarm_type': 0,
'zone_physical_type': 3,
'zone_type': 102,
'tampered': False,
},
'entity_id': 'binary_sensor.my_keyfob_sensor',
'state': 'on',
},
]
self._check_entity_states(ctx, expected_states, msg='Panel events')

Expand Down
25 changes: 24 additions & 1 deletion tests/integration/test_qolsys_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from qolsys.sensors import QolsysSensorFreeze
from qolsys.sensors import QolsysSensorGlassBreak
from qolsys.sensors import QolsysSensorHeat
from qolsys.sensors import QolsysSensorKeyFob
from qolsys.sensors import QolsysSensorKeypad
from qolsys.sensors import QolsysSensorMotion
from qolsys.sensors import QolsysSensorPanelGlassBreak
Expand Down Expand Up @@ -256,7 +257,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(7, len(partition1.sensors))
self.assertEqual(8, len(partition1.sensors))
self.assertEqual(1, partition1.id)
self.assertEqual('partition1', partition1.name)
self.assertEqual('DISARM', partition1.status)
Expand Down Expand Up @@ -645,6 +646,28 @@ async def test_integration_event_info_summary_initializes_all_entities(self):
expected_enabled_by_default=False,
)

with self.subTest(msg='Sensor 270 is properly configured'):
sensor270 = partition1.zone(270)
self.assertEqual(QolsysSensorKeyFob, sensor270.__class__)
self.assertEqual('002-0070', sensor270.id)
self.assertEqual('My KeyFob Sensor', sensor270.name)
self.assertEqual('mobileintrusion', sensor270.group)
self.assertEqual('Closed', sensor270.status)
self.assertEqual('0', sensor270.state)
self.assertEqual(270, sensor270.zone_id)
self.assertEqual(3, sensor270.zone_physical_type)
self.assertEqual(0, sensor270.zone_alarm_type)
self.assertEqual(102, sensor270.zone_type)
self.assertEqual(1, sensor270.partition_id)

await self._check_sensor_mqtt_messages(
gw=gw,
sensor_flat_name='my_keyfob_sensor',
sensor_state=sensor270,
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 @@ -245,6 +245,19 @@ def get_summary(secure_arm=False, partition_ids=None,
'zone_type': 14,
'partition_id': 1,
},
{
'id': '002-0070',
'type': 'KeyFob',
'name': 'My KeyFob Sensor',
'group': 'mobileintrusion',
'status': 'Closed',
'state': '0',
'zone_id': 270,
'zone_physical_type': 3,
'zone_alarm_type': 0,
'zone_type': 102,
'partition_id': 1,
},
],
},
],
Expand Down

0 comments on commit 0da482e

Please sign in to comment.