Skip to content

Commit

Permalink
Merge pull request #388 from tekand/fix-numeric-sensor
Browse files Browse the repository at this point in the history
Signal_strength exposed as numeric sensor
  • Loading branch information
yozik04 authored Sep 18, 2023
2 parents 6a82adb + 768e1ee commit 0ad0e20
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
5 changes: 4 additions & 1 deletion paradox/interfaces/mqtt/entities/factory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from paradox.interfaces.mqtt.entities.alarm_control_panel import AlarmControlPanel
from paradox.interfaces.mqtt.entities.binary_sensors import ZoneStatusBinarySensor, \
SystemBinarySensor, PartitionBinarySensor
from paradox.interfaces.mqtt.entities.sensor import PAIStatusSensor, SystemStatusSensor
from paradox.interfaces.mqtt.entities.sensor import PAIStatusSensor, SystemStatusSensor, ZoneNumericSensor
from paradox.interfaces.mqtt.entities.switch import ZoneBypassSwitch, PGMSwitch


Expand All @@ -28,6 +28,9 @@ def make_zone_bypass_switch(self, zone):
def make_zone_status_binary_sensor(self, zone, status):
return ZoneStatusBinarySensor(zone, status, self.device, self.availability_topic)

def make_zone_status_numeric_sensor(self, zone, status):
return ZoneNumericSensor(zone, status, self.device, self.availability_topic)

def make_pgm_switch(self, pgm):
return PGMSwitch(pgm, self.device, self.availability_topic)

Expand Down
13 changes: 13 additions & 0 deletions paradox/interfaces/mqtt/entities/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ def entity_name(self):
return "PAI Status"


class ZoneNumericSensor(AbstractEntity):
def __init__(self, entity, property, device, availability_topic):
super().__init__(device, availability_topic)

self.property = property
self.label = entity.get("label", entity["key"].replace("_", " "))

self.key = sanitize_key(entity["key"])

self.pai_entity_type = "zone"
self.hass_entity_type = "sensor"


class SystemStatusSensor(AbstractEntity):
def __init__(self, key, property, device, availability_topic):
super().__init__(device, availability_topic)
Expand Down
8 changes: 5 additions & 3 deletions paradox/interfaces/mqtt/homeassistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,12 @@ def _publish_zone_configs(self, zone_statuses):
if property_name not in cfg.HOMEASSISTANT_PUBLISH_ZONE_PROPERTIES:
continue
if property_name == "bypassed":
zone_status_binary_sensor = self.entity_factory.make_zone_bypass_switch(zone)
zone_status_sensor = self.entity_factory.make_zone_bypass_switch(zone)
elif property_name == "signal_strength":
zone_status_sensor = self.entity_factory.make_zone_status_numeric_sensor(zone, property_name)
else:
zone_status_binary_sensor = self.entity_factory.make_zone_status_binary_sensor(zone, property_name)
self._publish_config(zone_status_binary_sensor)
zone_status_sensor = self.entity_factory.make_zone_status_binary_sensor(zone, property_name)
self._publish_config(zone_status_sensor)

def _publish_pgm_configs(self, pgm_statuses):
for pgm_key, pgm_status in pgm_statuses.items():
Expand Down

0 comments on commit 0ad0e20

Please sign in to comment.