Skip to content

Commit

Permalink
Backout state prop change
Browse files Browse the repository at this point in the history
  • Loading branch information
sebr committed Mar 4, 2020
1 parent 36e8ffd commit d9a47df
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
5 changes: 0 additions & 5 deletions custom_components/bhyve/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,6 @@ def should_poll(self):
"""Disable polling."""
return False

@property
def state(self):
"""Return the state of the entity"""
return self._state

@property
def unique_id(self):
"""Return a unique, unchanging string that represents this sensor."""
Expand Down
10 changes: 10 additions & 0 deletions custom_components/bhyve/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def _setup(self, device):
self._state = battery["percent"]
self._attrs[ATTR_BATTERY_LEVEL] = battery["percent"]

@property
def state(self):
"""Return the state of the entity"""
return self._state

@property
def unit_of_measurement(self):
"""Return the unit of measurement for the sensor."""
Expand Down Expand Up @@ -95,6 +100,11 @@ def _setup(self, device):
self._state = device.get("status", {}).get("run_mode")
self._available = device.get("is_connected", False)

@property
def state(self):
"""Return the state of the entity"""
return self._state

def _on_ws_data(self, data):
"""
{'event': 'change_mode', 'mode': 'auto', 'device_id': 'id', 'timestamp': '2020-01-09T20:30:00.000Z'}
Expand Down
16 changes: 8 additions & 8 deletions custom_components/bhyve/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self, hass, bhyve, device, zone, name, programs, icon):
super().__init__(hass, bhyve, device, name, icon, DEVICE_CLASS_SWITCH)

def _setup(self, device):
self._state = None
self._is_on = False
self._attrs = {}
self._available = device.get("is_connected", False)

Expand All @@ -87,7 +87,7 @@ def _setup(self, device):
watering_status is not None
and watering_status.get("current_station") == self._zone_id
)
self._state = is_watering
self._is_on = is_watering
self._attrs = {ATTR_MANUAL_RUNTIME: self._manual_preset_runtime}

smart_watering_enabled = zone.get("smart_watering_enabled")
Expand Down Expand Up @@ -201,17 +201,17 @@ def _on_ws_data(self, data):
_LOGGER.warning("No event on ws data {}".format(data))
return
elif event == "device_idle" or event == "watering_complete":
self._state = False
self._is_on = False
self._set_watering_started(None)
elif event == "watering_in_progress_notification":
zone = data.get("current_station")
if zone == self._zone_id:
self._state = True
self._is_on = True
started_watering_at = data.get("started_watering_station_at")
self._set_watering_started(started_watering_at)
elif event == "change_mode":
program = data.get("program")
self._state = program == PROGRAM_SMART_WATERING or program == PROGRAM_MANUAL
self._is_on = program == PROGRAM_SMART_WATERING or program == PROGRAM_MANUAL
elif event == "set_manual_preset_runtime":
self._manual_preset_runtime = data.get("seconds")
self._attrs[ATTR_MANUAL_RUNTIME] = self._manual_preset_runtime
Expand Down Expand Up @@ -254,19 +254,19 @@ def unique_id(self):
@property
def is_on(self):
"""Return the status of the sensor."""
return self._state is True
return self._is_on

async def async_turn_on(self, **kwargs):
"""Turn the switch on."""
station_payload = [
{"station": self._zone_id, "run_time": self._manual_preset_runtime}
]
self._state = True
self._is_on = True
await self._send_station_message(station_payload)

async def async_turn_off(self, **kwargs):
"""Turn the switch off."""
station_payload = []
self._state = False
self._is_on = False
await self._send_station_message(station_payload)

0 comments on commit d9a47df

Please sign in to comment.