From f48279eda74681e31911c40aac331b5e5f430c54 Mon Sep 17 00:00:00 2001 From: Seb Ruiz Date: Wed, 14 Aug 2024 10:58:28 +1000 Subject: [PATCH] Set flood sensor temperature units (#258) * 257: Set native_value and native_unit_of_measurement for flood sensors --- custom_components/bhyve/manifest.json | 2 +- custom_components/bhyve/sensor.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/custom_components/bhyve/manifest.json b/custom_components/bhyve/manifest.json index 2896f02..8c74e80 100644 --- a/custom_components/bhyve/manifest.json +++ b/custom_components/bhyve/manifest.json @@ -7,5 +7,5 @@ "documentation": "https://github.com/sebr/bhyve-home-assistant/blob/main/README.md", "iot_class": "cloud_push", "requirements": [], - "version": "3.2.4" + "version": "3.2.5-beta0" } diff --git a/custom_components/bhyve/sensor.py b/custom_components/bhyve/sensor.py index 218dbfe..3c227ff 100644 --- a/custom_components/bhyve/sensor.py +++ b/custom_components/bhyve/sensor.py @@ -1,17 +1,16 @@ """Support for Orbit BHyve sensors.""" -import logging from datetime import timedelta +import logging +from homeassistant.components.sensor import SensorDeviceClass from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_BATTERY_LEVEL +from homeassistant.const import ATTR_BATTERY_LEVEL, SensorStateClass, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.icon import icon_for_battery_level -from homeassistant.components.sensor import SensorDeviceClass - from . import BHyveDeviceEntity from .const import ( CONF_CLIENT, @@ -343,9 +342,11 @@ def __init__(self, hass, bhyve, device): ) def _setup(self, device): - self._state = device.get("status", {}).get("temp_f") self._available = device.get("is_connected", False) - self._unit = "°F" + self._native_value = device.get("status", {}).get("temp_f") + self._native_unit_of_measurement = UnitOfTemperature.FAHRENHEIT + self._state_class = SensorStateClass.MEASUREMENT + self._attrs = { "location": device.get("location_name"), "rssi": device.get("status", {}).get("rssi"),