Skip to content

Commit

Permalink
enable binary_sensor for smart gardena
Browse files Browse the repository at this point in the history
  • Loading branch information
grm committed Jun 6, 2020
1 parent 11fa83b commit 2794c6f
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions custom_components/gardena_smart_system/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Support for Gardena Smart System websocket connection status."""
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_CONNECTIVITY,
BinarySensorEntity,
)

Expand All @@ -9,11 +10,11 @@

async def async_setup_entry(hass, config_entry, async_add_entities):
"""Perform the setup for Gardena websocket connection status."""
async_add_entities([SmartSystemWebsocketStatus(hass.data[DOMAIN][GARDENA_SYSTEM])], True)
async_add_entities([SmartSystemWebsocketStatus(hass.data[DOMAIN][GARDENA_SYSTEM].smart_system)], True)


class SmartSystemWebsocketStatus(BinarySensorEntity):
"""Representation of an InComfort Failed sensor."""
"""Representation of Gardena Smart System websocket connection status."""

def __init__(self, smart_system) -> None:
"""Initialize the binary sensor."""
Expand All @@ -22,16 +23,35 @@ def __init__(self, smart_system) -> None:
self._name = "Gardena Smart System connection"
self._smart_system = smart_system

async def async_added_to_hass(self):
"""Subscribe to events."""
self._smart_system.add_ws_status_callback(self.update_callback)

@property
def name(self):
"""Return the name of the device."""
return self._name

@property
def unique_id(self) -> str:
"""Return a unique ID."""
return self._unique_id

@property
def is_on(self) -> bool:
"""Return the status of the sensor."""
return self._smart_system.ws_status == "ONLINE"
return self._smart_system.is_ws_connected

@property
def should_poll(self) -> bool:
"""No polling needed for a sensor."""
return False

def update_callback(self, device):
def update_callback(self):
"""Call update for Home Assistant when the device is updated."""
self.schedule_update_ha_state(True)

@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_CONNECTIVITY

0 comments on commit 2794c6f

Please sign in to comment.