Skip to content

Commit

Permalink
Merge pull request #82 from mattsaxon/issue#80
Browse files Browse the repository at this point in the history
Add Query Button
  • Loading branch information
tahvane1 authored Mar 4, 2022
2 parents 3fae08e + f9c3943 commit a602335
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion custom_components/jablotron80/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,7 +13,7 @@
from .jablotron import JA80CentralUnit
# List of platforms to support. There should be a matching .py file for each,
# eg <cover.py> and <sensor.py>
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):
Expand Down
26 changes: 26 additions & 0 deletions custom_components/jablotron80/button.py
Original file line number Diff line number Diff line change
@@ -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."""
11 changes: 10 additions & 1 deletion custom_components/jablotron80/jablotron.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,8 @@ def is_alarm_state(status):
return status in JablotronState.STATES_ALARM



class JablotronButton(JablotronCommon):
pass

class JablotronLed(JablotronCommon):
pass
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a602335

Please sign in to comment.