Skip to content

Commit

Permalink
✨ [feature] Add support for Shock sensor (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbuckley4192 authored Jan 13, 2024
1 parent daf702b commit b324b54
Show file tree
Hide file tree
Showing 5 changed files with 73 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 @@ -20,6 +20,7 @@
from qolsys.sensors import QolsysSensorKeyFob
from qolsys.sensors import QolsysSensorKeypad
from qolsys.sensors import QolsysSensorMotion
from qolsys.sensors import QolsysSensorShock
from qolsys.sensors import QolsysSensorSiren
from qolsys.sensors import QolsysSensorSmokeDetector
from qolsys.sensors import QolsysSensorTakeoverModule
Expand Down Expand Up @@ -443,6 +444,7 @@ class MqttWrapperQolsysSensor(MqttWrapper):
QolsysSensorKeyFob: 'safety',
QolsysSensorKeypad: 'safety',
QolsysSensorMotion: 'motion',
QolsysSensorShock: 'vibration',
QolsysSensorSiren: 'safety',
QolsysSensorSmokeDetector: 'smoke',
QolsysSensorTakeoverModule: 'safety',
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 @@ -374,3 +374,9 @@ class QolsysSensorDoorbell(QolsysSensor):
@classmethod
def from_json(cls, data, partition, common=None):
return cls.from_json_subclass('Doorbell', data, partition, common)


class QolsysSensorShock(QolsysSensor):
@classmethod
def from_json(cls, data, partition, common=None):
return cls.from_json_subclass('Shock', data, partition, common)
27 changes: 27 additions & 0 deletions tests/end-to-end/test_qolsysgw.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,19 @@ async def _check_initial_state(self, ctx):
'entity_id': 'binary_sensor.qolsys_panel_my_translator_sensor',
'state': 'off',
},
{
'attributes': {
'device_class': 'vibration',
'friendly_name': 'Qolsys Panel My Shock Sensor',
'group': 'shock',
'zone_alarm_type': 0,
'zone_physical_type': 12,
'zone_type': 107,
'tampered': False,
},
'entity_id': 'binary_sensor.qolsys_panel_my_shock_sensor',
'state': 'off',
},
]
self._check_entity_states(ctx, expected_states, msg='Initial state')

Expand Down Expand Up @@ -590,6 +603,7 @@ async def _check_panel_events(self, ctx):
20080,
200802,
20081,
20090,
]
open_entities = [
10001,
Expand Down Expand Up @@ -1014,6 +1028,19 @@ def zone_active_event(zone_id, closed=False):
'entity_id': 'binary_sensor.qolsys_panel_my_translator_sensor',
'state': 'on',
},
{
'attributes': {
'device_class': 'vibration',
'friendly_name': 'Qolsys Panel My Shock Sensor',
'group': 'shock',
'zone_alarm_type': 0,
'zone_physical_type': 12,
'zone_type': 107,
'tampered': False,
},
'entity_id': 'binary_sensor.qolsys_panel_my_shock_sensor',
'state': 'on',
},
]
self._check_entity_states(ctx, expected_states, msg='Panel events')

Expand Down
26 changes: 25 additions & 1 deletion tests/integration/test_qolsys_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from qolsys.sensors import QolsysSensorMotion
from qolsys.sensors import QolsysSensorPanelGlassBreak
from qolsys.sensors import QolsysSensorPanelMotion
from qolsys.sensors import QolsysSensorShock
from qolsys.sensors import QolsysSensorSiren
from qolsys.sensors import QolsysSensorSmokeDetector
from qolsys.sensors import QolsysSensorTakeoverModule
Expand Down Expand Up @@ -261,7 +262,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(13, len(partition1.sensors))
self.assertEqual(14, len(partition1.sensors))
self.assertEqual(1, partition1.id)
self.assertEqual('partition1', partition1.name)
self.assertEqual('DISARM', partition1.status)
Expand Down Expand Up @@ -805,6 +806,29 @@ async def test_integration_event_info_summary_initializes_all_entities(self):
expected_enabled_by_default=False,
)

with self.subTest(msg='Sensor 20090 is properly configured'):
sensor20090 = partition1.zone(20090)
self.assertEqual(QolsysSensorShock, sensor20090.__class__)
self.assertEqual('002-0090', sensor20090.id)
self.assertEqual('My Shock Sensor', sensor20090.name)
self.assertEqual('shock', sensor20090.group)
self.assertEqual('Closed', sensor20090.status)
self.assertEqual('0', sensor20090.state)
self.assertEqual(20090, sensor20090.zone_id)
self.assertEqual(12, sensor20090.zone_physical_type)
self.assertEqual(0, sensor20090.zone_alarm_type)
self.assertEqual(107, sensor20090.zone_type)
self.assertEqual(1, sensor20090.partition_id)

await self._check_sensor_mqtt_messages(
gw=gw,
sensor_flat_name='my_shock_sensor',
sensor_unique_id='002_0090',
sensor_state=sensor20090,
expected_device_class='vibration',
expected_enabled_by_default=True,
)

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 @@ -323,6 +323,19 @@ def get_summary(secure_arm=False, partition_ids=None,
'zone_type': 20,
'partition_id': 1,
},
{
'id': '002-0090',
'type': 'Shock',
'name': 'My Shock Sensor',
'group': 'shock',
'status': 'Closed',
'state': '0',
'zone_id': 20090,
'zone_physical_type': 12,
'zone_alarm_type': 0,
'zone_type': 107,
'partition_id': 1,
},
],
},
],
Expand Down

0 comments on commit b324b54

Please sign in to comment.