Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a sensor that lists all faults #26

Merged
merged 5 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion custom_components/bosch_alarm/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"homekit": {},
"iot_class": "local_push",
"issue_tracker": "https://github.com/mag1024/bosch-alarm-homeassistant/issues",
"requirements": ["bosch-alarm-mode2==0.3.29"],
"requirements": ["bosch-alarm-mode2==0.3.32"],
"ssdp": [],
"version": "0.1.0",
"zeroconf": []
Expand Down
31 changes: 30 additions & 1 deletion custom_components/bosch_alarm/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,39 @@ async def async_added_to_hass(self):

async def async_will_remove_from_hass(self):
self._panel.history_observer.detach(self.schedule_update_ha_state)
class PanelFaultsSensor(SensorEntity):
def __init__(self, panel):
self._panel = panel
self._attr_device_info = device_info_from_panel(panel)
sanjay900 marked this conversation as resolved.
Show resolved Hide resolved

@property
def icon(self): return "mdi:alert-circle"

@property
def unique_id(self): return f'{self._panel.serial_number}_faults'

@property
def should_poll(self): return False

@property
def state(self):
faults = self._panel.panel_faults
if faults:
sanjay900 marked this conversation as resolved.
Show resolved Hide resolved
return "\n".join(faults)
return "No faults"

@property
def name(self): return f"{self._panel.model} Faults"

async def async_added_to_hass(self):
self._panel.faults_observer.attach(self.schedule_update_ha_state)

async def async_will_remove_from_hass(self):
self._panel.faults_observer.detach(self.schedule_update_ha_state)

async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up a sensor for tracking panel history."""

panel = hass.data[DOMAIN][config_entry.entry_id]
async_add_entities([PanelHistorySensor(panel)])
async_add_entities([PanelHistorySensor(panel), PanelFaultsSensor(panel)])