diff --git a/custom_components/jablotron80/__init__.py b/custom_components/jablotron80/__init__.py index 52caf2a..58845a7 100644 --- a/custom_components/jablotron80/__init__.py +++ b/custom_components/jablotron80/__init__.py @@ -3,6 +3,7 @@ from homeassistant.components.alarm_control_panel import DOMAIN as PLATFORM_ALARM_CONTROL_PANEL from homeassistant.components.binary_sensor import DOMAIN as PLATFORM_BINARY_SENSOR from homeassistant.components.sensor import DOMAIN as PLATFORM_SENSOR +from homeassistant.components.button import DOMAIN as PLATFORM_BUTTON from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr @@ -12,7 +13,7 @@ from .jablotron import JA80CentralUnit # List of platforms to support. There should be a matching .py file for each, # eg and -PLATFORMS = [PLATFORM_ALARM_CONTROL_PANEL,PLATFORM_BINARY_SENSOR,PLATFORM_SENSOR] +PLATFORMS = [PLATFORM_ALARM_CONTROL_PANEL,PLATFORM_BINARY_SENSOR,PLATFORM_SENSOR, PLATFORM_BUTTON] async def async_setup(hass: HomeAssistant, config: dict): diff --git a/custom_components/jablotron80/button.py b/custom_components/jablotron80/button.py new file mode 100644 index 0000000..6021583 --- /dev/null +++ b/custom_components/jablotron80/button.py @@ -0,0 +1,26 @@ +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.components.button import ButtonEntity +from .jablotron import JA80CentralUnit, JablotronButton +from .jablotronHA import JablotronEntity +from typing import Optional +from .const import ( + DATA_JABLOTRON, + DOMAIN) + + +import logging +LOGGER = logging.getLogger(__package__) +async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities) -> None: + cu = hass.data[DOMAIN][config_entry.entry_id][DATA_JABLOTRON] # type: JA80CentralUnit + async_add_entities([JablotronQueryButtonEntity(cu.query,cu)], True) + +class JablotronQueryButtonEntity(JablotronEntity, ButtonEntity): + + def __init__(self, button: JablotronButton,cu: JA80CentralUnit) -> None: + super().__init__(cu, button) + + async def async_press(self) -> None: + + self._cu._send_device_query() + """Handle the button press.""" diff --git a/custom_components/jablotron80/jablotron.py b/custom_components/jablotron80/jablotron.py index a2d6849..f0674b1 100644 --- a/custom_components/jablotron80/jablotron.py +++ b/custom_components/jablotron80/jablotron.py @@ -1064,7 +1064,8 @@ def is_alarm_state(status): return status in JablotronState.STATES_ALARM - +class JablotronButton(JablotronCommon): + pass class JablotronLed(JablotronCommon): pass @@ -1202,6 +1203,10 @@ def __init__(self, hass: HomeAssistant, config: Dict[str, Any], options: Dict[s self._statustext.name = f'{CENTRAL_UNIT_MODEL} Status Text' self._statustext.type = "status" + self._query = JablotronButton(4) + self._query.name = f'{CENTRAL_UNIT_MODEL} Query Button' + self._query.type = "button" + self._active_devices = {} self._active_codes = {} self._codes = {} @@ -1345,6 +1350,10 @@ def statustext(self) -> JablotronStatusText: def statustext(self,statustext: str) -> None: self._statustext.message = statustext + @property + def query(self) -> JablotronButton: + return self._query + @property def system_status(self) -> str: return self._system_status