Skip to content

Commit

Permalink
feat: add outputs status and command
Browse files Browse the repository at this point in the history
  • Loading branch information
xtimmy86x committed Dec 1, 2023
1 parent f10312e commit da7bbfc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions custom_components/econnect_metronet/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
CONF_AREAS_ARM_VACATION = "areas_arm_vacation"
CONF_SCAN_INTERVAL = "scan_interval"
DOMAIN = "econnect_metronet"
NOTIFICATION_MESSAGE = (
"The switch cannot be used because it is not properly configured in the alarm control panel. "
"Please contact your installer to enable it."
)
NOTIFICATION_TITLE = "Unable to toggle the switch"
NOTIFICATION_IDENTIFIER = "econnect_metronet_output_fail"
KEY_DEVICE = "device"
KEY_COORDINATOR = "coordinator"
KEY_UNSUBSCRIBER = "options_unsubscriber"
Expand Down
4 changes: 4 additions & 0 deletions custom_components/econnect_metronet/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,11 @@ def turn_off(self, output):
try:
element_id = item.get("element")
self._connection.turn_off(element_id)
return True
except HTTPError as err:
_LOGGER.error(f"Device | Error while turning off output: {err.response.text}")
raise err
return False

def turn_on(self, output):
"""
Expand Down Expand Up @@ -390,6 +392,8 @@ def turn_on(self, output):
try:
element_id = item.get("element")
self._connection.turn_on(element_id)
return True
except HTTPError as err:
_LOGGER.error(f"Device | Error while turning on outputs: {err.response.text}")
raise err
return False
16 changes: 14 additions & 2 deletions custom_components/econnect_metronet/switch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from elmo import query as q
from homeassistant.components import persistent_notification
from homeassistant.components.switch import SwitchEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
Expand All @@ -14,6 +15,9 @@
DOMAIN,
KEY_COORDINATOR,
KEY_DEVICE,
NOTIFICATION_IDENTIFIER,
NOTIFICATION_MESSAGE,
NOTIFICATION_TITLE,
)
from .devices import AlarmDevice
from .helpers import generate_entity_id
Expand Down Expand Up @@ -84,8 +88,16 @@ def is_on(self) -> bool:

async def async_turn_off(self):
"""Turn the entity off."""
await self.hass.async_add_executor_job(self._device.turn_off, self._output_id) # pragma: no cover
# await self.hass.async_add_executor_job(self._device.turn_off, self._output_id) # pragma: no cover
if not await self.hass.async_add_executor_job(self._device.turn_off, self._output_id):
persistent_notification.async_create(
self.hass, NOTIFICATION_MESSAGE, NOTIFICATION_TITLE, NOTIFICATION_IDENTIFIER
)

async def async_turn_on(self):
"""Turn the entity off."""
await self.hass.async_add_executor_job(self._device.turn_on, self._output_id) # pragma: no cover
# await self.hass.async_add_executor_job(self._device.turn_on, self._output_id) # pragma: no cover
if not await self.hass.async_add_executor_job(self._device.turn_on, self._output_id):
persistent_notification.async_create(
self.hass, NOTIFICATION_MESSAGE, NOTIFICATION_TITLE, NOTIFICATION_IDENTIFIER
)

0 comments on commit da7bbfc

Please sign in to comment.