Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 4 additions & 28 deletions homeassistant/components/rachio/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
KEY_STATUS,
KEY_SUBTYPE,
SIGNAL_RACHIO_CONTROLLER_UPDATE,
STATUS_OFFLINE,
STATUS_ONLINE,
)
from .entity import RachioDevice
Expand All @@ -41,13 +40,10 @@ def _create_entities(hass, config_entry):
class RachioControllerBinarySensor(RachioDevice, BinarySensorEntity):
"""Represent a binary sensor that reflects a Rachio state."""

def __init__(self, controller, poll=True):
def __init__(self, controller):
"""Set up a new Rachio controller binary sensor."""
super().__init__(controller)
if poll:
self._state = self._poll_update()
else:
self._state = None
self._state = None

@property
def is_on(self) -> bool:
Expand All @@ -64,16 +60,14 @@ def _async_handle_any_update(self, *args, **kwargs) -> None:
# For this device
self._async_handle_update(args, kwargs)

@abstractmethod
def _poll_update(self, data=None) -> bool:
"""Request the state from the API."""

@abstractmethod
def _async_handle_update(self, *args, **kwargs) -> None:
"""Handle an update to the state of this sensor."""

async def async_added_to_hass(self):
"""Subscribe to updates."""
self._state = self._controller.init_data[KEY_STATUS] == STATUS_ONLINE
Comment thread
brg468 marked this conversation as resolved.
Outdated

self.async_on_remove(
async_dispatcher_connect(
self.hass,
Expand All @@ -86,11 +80,6 @@ async def async_added_to_hass(self):
class RachioControllerOnlineBinarySensor(RachioControllerBinarySensor):
"""Represent a binary sensor that reflects if the controller is online."""

def __init__(self, controller):
"""Set up a new Rachio controller online binary sensor."""
super().__init__(controller, poll=False)
self._state = self._poll_update(controller.init_data)

@property
def name(self) -> str:
"""Return the name of this sensor including the controller name."""
Expand All @@ -111,19 +100,6 @@ def icon(self) -> str:
"""Return the name of an icon for this sensor."""
return "mdi:wifi-strength-4" if self.is_on else "mdi:wifi-strength-off-outline"

def _poll_update(self, data=None) -> bool:
"""Request the state from the API."""
if data is None:
data = self._controller.rachio.device.get(self._controller.controller_id)[1]

if data[KEY_STATUS] == STATUS_ONLINE:
return True
if data[KEY_STATUS] == STATUS_OFFLINE:
return False
_LOGGER.warning(
'"%s" reported in unknown state "%s"', self.name, data[KEY_STATUS]
)

@callback
def _async_handle_update(self, *args, **kwargs) -> None:
"""Handle an update to the state of this sensor."""
Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/rachio/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
)

STATUS_ONLINE = "ONLINE"
STATUS_OFFLINE = "OFFLINE"

SIGNAL_RACHIO_UPDATE = f"{DOMAIN}_update"
SIGNAL_RACHIO_CONTROLLER_UPDATE = f"{SIGNAL_RACHIO_UPDATE}_controller"
Expand Down