Skip to content

Commit

Permalink
Test Siren button
Browse files Browse the repository at this point in the history
  • Loading branch information
Minims committed Aug 8, 2023
1 parent 428bdc2 commit 9d9d7ff
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
29 changes: 28 additions & 1 deletion somfyProtect2Mqtt/business/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,34 @@ def ha_devices_config(
payload=key_fob_config.get("config"),
retain=True,
)

if "mss_outdoor_siren" in device.device_definition.get("device_definition_id"):
mss_outdoor_siren = ha_discovery_devices(
site_id=site_id,
device=device,
mqtt_config=mqtt_config,
sensor_name="test_siren1s",
)
mqtt_publish(
mqtt_client=mqtt_client,
topic=mss_outdoor_siren.get("topic"),
payload=mss_outdoor_siren.get("config"),
retain=True,
)
if "mss_siren" in device.device_definition.get("device_definition_id"):
for sensor in ["smokeExtended", "siren1s", "armed", "disarmed", "intrusion", "ok"]:
LOGGER.info(f"Found mss_siren, adding sound test: {sensor}")
mss_siren = ha_discovery_devices(
site_id=site_id,
device=device,
mqtt_config=mqtt_config,
sensor_name=f"test_{sensor}",
)
mqtt_publish(
mqtt_client=mqtt_client,
topic=mss_siren.get("topic"),
payload=mss_siren.get("config"),
retain=True,
)
if "pir" in device.device_definition.get("type") or "tag" in device.device_definition.get("type"):
LOGGER.info(f"Found Motion Sensor (PIR & IntelliTag) {device.device_definition.get('label')}")
pir_config = ha_discovery_devices(
Expand Down
14 changes: 14 additions & 0 deletions somfyProtect2Mqtt/business/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ def consume_mqtt_message(msg, mqtt_config: dict, api: SomfyProtectApi, mqtt_clie
LOGGER.info(f"Stop the Siren On Site ID {site_id}")
api.stop_alarm(site_id=site_id)

elif text_payload in [
"test_smokeExtended",
"test_siren1s",
"test_armed",
"test_disarmed",
"test_intrusion",
"test_ok",
]:
site_id = msg.topic.split("/")[1]
device_id = msg.topic.split("/")[2]
sound = text_payload.split("_")[1]
LOGGER.info(f"Test the Siren On Site ID {site_id} ({sound})")
api.test_siren(site_id=site_id, device_id=device_id, sound=sound)

# Manage Actions
elif text_payload in ACTION_LIST:
site_id = msg.topic.split("/")[1]
Expand Down
24 changes: 24 additions & 0 deletions somfyProtect2Mqtt/homeassistant/ha_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,30 @@
"type": "button",
"config": {"payload_press": "halt"},
},
"test_smokeExtended": {
"type": "button",
"config": {"payload_press": "test_smokeExtended"},
},
"test_siren1s": {
"type": "button",
"config": {"payload_press": "test_siren1s"},
},
"test_armed": {
"type": "button",
"config": {"payload_press": "test_armed"},
},
"test_disarmed": {
"type": "button",
"config": {"payload_press": "test_disarmed"},
},
"test_intrusion": {
"type": "button",
"config": {"payload_press": "test_intrusion"},
},
"test_ok": {
"type": "button",
"config": {"payload_press": "test_ok"},
},
"gate": {
"type": "switch",
"config": {
Expand Down
16 changes: 16 additions & 0 deletions somfyProtect2Mqtt/somfy_protect/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,19 @@ def get_scenarios(
response = self.get(f"/v3/site/{site_id}/scenario")
response.raise_for_status()
return response.json()

def test_siren(self, site_id: str, device_id: str, sound: str) -> Dict:
"""Test Siren
Args:
site_id (str): Site ID
device_id (str) Device ID
sound (str): Sound (smokeExtended, siren1s, armed, disarmed, intrusion, ok)
Returns:
Dict: requests Response object
"""
if sound not in ["smokeExtended", "siren1s", "armed", "disarmed", "intrusion", "ok"]:
raise ValueError("Sound value is not valid")
response = self.post(f"/v3/site/{site_id}/device/{device_id}/sound/{sound}", json={})
response.raise_for_status()
return response.json()

0 comments on commit 9d9d7ff

Please sign in to comment.