Skip to content

Commit

Permalink
Until BHyveTemperatureSensor implements SensorEntity we need to i…
Browse files Browse the repository at this point in the history
…mplement the `state()` property
  • Loading branch information
sebr committed Nov 9, 2021
1 parent 5a7e9c5 commit 87bb3b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
16 changes: 6 additions & 10 deletions custom_components/bhyve/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
DATA_BHYVE,
DEVICE_FLOOD,
EVENT_FS_ALARM,
EVENT_DEVICE_IDLE,
)
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_MOISTURE
)
from homeassistant.components.binary_sensor import DEVICE_CLASS_MOISTURE
from .pybhyve.errors import BHyveError
from .util import orbit_time_to_local_time

_LOGGER = logging.getLogger(__name__)

Expand All @@ -29,7 +25,7 @@ async def async_setup_platform(hass, config, async_add_entities, _discovery_info

async_add_entities(sensors, True)


class BHyveFloodSensor(BHyveDeviceEntity):
"""Define a BHyve sensor."""

Expand Down Expand Up @@ -58,25 +54,25 @@ def _parse_status(self, status):
def state(self):
"""Return the state of the entity"""
return self._state

@property
def unique_id(self):
"""Return the unique id."""
return f"{self._mac_address}:{self._device_id}:water"

@property
def is_on(self):
return self._state == "on"

def _on_ws_data(self, data):
"""
{"last_flood_alarm_at":"2021-08-29T16:32:35.585Z","rssi":-60,"onboard_complete":true,"temp_f":75.2,"provisioned":true,"phy":"le_1m_1000","event":"fs_status_update","temp_alarm_status":"ok","status_updated_at":"2021-08-29T16:33:17.089Z","identify_enabled":false,"device_id":"612ad9134f0c6c9c9faddbba","timestamp":"2021-08-29T16:33:17.089Z","flood_alarm_status":"ok","last_temp_alarm_at":null}
{"last_flood_alarm_at":"2021-08-29T16:32:35.585Z","rssi":-60,"onboard_complete":true,"temp_f":75.2,"provisioned":true,"phy":"le_1m_1000","event":"fs_status_update","temp_alarm_status":"ok","status_updated_at":"2021-08-29T16:33:17.089Z","identify_enabled":false,"device_id":"612ad9134f0c6c9c9faddbba","timestamp":"2021-08-29T16:33:17.089Z","flood_alarm_status":"ok","last_temp_alarm_at":null}
"""
_LOGGER.info("Received program data update {}".format(data))
event = data.get("event")
if event == EVENT_FS_ALARM:
self._state = self._parse_status(data)
self._attrs['rssi'] = data.get("rssi")
self._attrs["rssi"] = data.get("rssi")

def _should_handle_event(self, event_name, data):
return event_name in [EVENT_FS_ALARM]
9 changes: 3 additions & 6 deletions custom_components/bhyve/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
DEVICE_CLASS_TEMPERATURE,
)

from . import BHyveDeviceEntity, WebsocketEntity
from . import BHyveDeviceEntity
from .const import (
DATA_BHYVE,
DEVICE_SPRINKLER,
Expand Down Expand Up @@ -293,11 +293,8 @@ def _setup(self, device):
)

@property
def native_unit_of_measurement(self):
return TEMP_FAHRENHEIT

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

@property
Expand Down

0 comments on commit 87bb3b6

Please sign in to comment.