Skip to content

Commit

Permalink
✨ [feature] Add support for Siren sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
XaF committed Feb 19, 2023
1 parent 9aa7c17 commit a4f468b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
2 changes: 2 additions & 0 deletions apps/qolsysgw/mqtt/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from qolsys.sensors import QolsysSensorHeat
from qolsys.sensors import QolsysSensorKeypad
from qolsys.sensors import QolsysSensorMotion
from qolsys.sensors import QolsysSensorSiren
from qolsys.sensors import QolsysSensorSmokeDetector
from qolsys.sensors import QolsysSensorTilt
from qolsys.sensors import QolsysSensorWater
Expand Down Expand Up @@ -440,6 +441,7 @@ class MqttWrapperQolsysSensor(MqttWrapper):
QolsysSensorTilt: 'garage_door',
QolsysSensorKeypad: 'safety',
QolsysSensorAuxiliaryPendant: 'safety',
QolsysSensorSiren: '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 @@ -314,3 +314,9 @@ class QolsysSensorAuxiliaryPendant(QolsysSensor, _QolsysSensorWithoutUpdates):
@classmethod
def from_json(cls, data, common=None):
return cls.from_json_subclass('Auxiliary Pendant', data, common)


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

Expand All @@ -472,7 +485,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]
200, 210, 220, 230, 240, 250, 260]
open_entities = [101]
tamper_entities = [100, 110, 111, 210]
untamper_entities_to_open = [100]
Expand Down Expand Up @@ -805,6 +818,19 @@ def zone_active_event(zone_id, closed=False):
'entity_id': 'binary_sensor.my_auxiliary_pendant_sensor',
'state': 'on',
},
{
'attributes': {
'device_class': 'safety',
'friendly_name': 'My Siren Sensor',
'group': 'Siren',
'zone_alarm_type': 3,
'zone_physical_type': 1,
'zone_type': 14,
'tampered': False,
},
'entity_id': 'binary_sensor.my_siren_sensor',
'state': 'on',
},
]
self._check_entity_states(ctx, expected_states, msg='Panel events')

Expand Down
23 changes: 23 additions & 0 deletions tests/integration/test_qolsys_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from qolsys.sensors import QolsysSensorMotion
from qolsys.sensors import QolsysSensorPanelGlassBreak
from qolsys.sensors import QolsysSensorPanelMotion
from qolsys.sensors import QolsysSensorSiren
from qolsys.sensors import QolsysSensorSmokeDetector
from qolsys.sensors import QolsysSensorTilt
from qolsys.sensors import QolsysSensorWater
Expand Down Expand Up @@ -622,6 +623,28 @@ async def test_integration_event_info_summary_initializes_all_entities(self):
expected_enabled_by_default=False,
)

with self.subTest(msg='Sensor 260 is properly configured'):
sensor260 = partition1.zone(260)
self.assertEqual(QolsysSensorSiren, sensor260.__class__)
self.assertEqual('002-0060', sensor260.id)
self.assertEqual('My Siren Sensor', sensor260.name)
self.assertEqual('Siren', sensor260.group)
self.assertEqual('Closed', sensor260.status)
self.assertEqual('0', sensor260.state)
self.assertEqual(260, sensor260.zone_id)
self.assertEqual(1, sensor260.zone_physical_type)
self.assertEqual(3, sensor260.zone_alarm_type)
self.assertEqual(14, sensor260.zone_type)
self.assertEqual(1, sensor260.partition_id)

await self._check_sensor_mqtt_messages(
gw=gw,
sensor_flat_name='my_siren_sensor',
sensor_state=sensor260,
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 @@ -232,6 +232,19 @@ def get_summary(secure_arm=False, partition_ids=None,
'zone_type': 21,
'partition_id': 1,
},
{
'id': '002-0060',
'type': 'Siren',
'name': 'My Siren Sensor',
'group': 'Siren',
'status': 'Closed',
'state': '0',
'zone_id': 260,
'zone_physical_type': 1,
'zone_alarm_type': 3,
'zone_type': 14,
'partition_id': 1,
},
],
},
],
Expand Down

0 comments on commit a4f468b

Please sign in to comment.