Skip to content

Commit

Permalink
Merge pull request #136 from jdrozdnovak/dev
Browse files Browse the repository at this point in the history
Fix for deprecated constants
  • Loading branch information
Andrey "Limych" Khrolenok authored Feb 27, 2024
2 parents 303adfe + 56444fa commit 7431213
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions custom_components/temperature_feels_like/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
DOMAIN as CLIMATE,
)
from homeassistant.components.group import expand_entity_ids
from homeassistant.components.number import NumberDeviceClass
from homeassistant.components.sensor import SensorEntity, SensorStateClass
from homeassistant.components.sensor import (
SensorEntity,
SensorStateClass,
SensorDeviceClass,
)
from homeassistant.components.weather import (
ATTR_WEATHER_HUMIDITY,
ATTR_WEATHER_TEMPERATURE,
Expand All @@ -26,8 +29,6 @@
CONF_NAME,
CONF_SOURCE,
CONF_UNIQUE_ID,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE,
EVENT_HOMEASSISTANT_START,
PERCENTAGE,
STATE_UNAVAILABLE,
Expand Down Expand Up @@ -97,7 +98,7 @@ class TemperatureFeelingSensor(SensorEntity):
"""temperature_feels_like Sensor class."""

_attr_icon = "mdi:thermometer-lines"
_attr_device_class = NumberDeviceClass.TEMPERATURE
_attr_device_class = SensorDeviceClass.TEMPERATURE
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
_attr_should_poll: bool = False
_attr_native_unit_of_measurement: str = UnitOfTemperature.CELSIUS
Expand Down Expand Up @@ -161,10 +162,12 @@ def sensor_startup(event):
state: State = self.hass.states.get(entity_id)
domain = split_entity_id(state.entity_id)[0]
device_class = state.attributes.get(ATTR_DEVICE_CLASS)
unit_of_measurement = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
unit_of_measurement = state.attributes.get(
ATTR_UNIT_OF_MEASUREMENT
)

if (
device_class == DEVICE_CLASS_TEMPERATURE
device_class == SensorDeviceClass.TEMPERATURE
or domain in (WEATHER, CLIMATE)
or unit_of_measurement in TEMPERATURE_UNITS
or entity_id.find("temperature") >= 0
Expand All @@ -173,7 +176,7 @@ def sensor_startup(event):
entities.add(entity_id)

if (
device_class == DEVICE_CLASS_HUMIDITY
device_class == SensorDeviceClass.HUMIDITY
or domain in (WEATHER, CLIMATE)
or unit_of_measurement == PERCENTAGE
or entity_id.find("humidity") >= 0
Expand All @@ -196,11 +199,15 @@ def sensor_startup(event):
self._name += " Temperature"
self._name += " Feels Like"

async_track_state_change(self.hass, list(entities), sensor_state_listener)
async_track_state_change(
self.hass, list(entities), sensor_state_listener
)

self.async_schedule_update_ha_state(True)

self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, sensor_startup)
self.hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_START, sensor_startup
)

@staticmethod
def _has_state(state) -> bool:
Expand Down Expand Up @@ -239,7 +246,9 @@ def _get_temperature(self, entity_id: Optional[str]) -> Optional[float]:
float(temperature), entity_unit, UnitOfTemperature.CELSIUS
)
except ValueError as exc:
_LOGGER.error('Could not convert value "%s" to float: %s', state, exc)
_LOGGER.error(
'Could not convert value "%s" to float: %s', state, exc
)
return None

return float(temperature)
Expand Down Expand Up @@ -299,7 +308,9 @@ async def async_update(self):
self._humd_val = humd = self._get_humidity(self._humd) # %
self._wind_val = wind = self._get_wind_speed(self._wind) # m/s

_LOGGER.debug("Temp: %s °C Hum: %s %% Wind: %s m/s", temp, humd, wind)
_LOGGER.debug(
"Temp: %s °C Hum: %s %% Wind: %s m/s", temp, humd, wind
)

if temp is None or humd is None:
_LOGGER.warning(
Expand All @@ -315,7 +326,9 @@ async def async_update(self):
wind = 0

e_value = humd * 0.06105 * math.exp((17.27 * temp) / (237.7 + temp))
self._attr_native_value = round(temp + 0.348 * e_value - 0.7 * wind - 4.25, 1)
self._attr_native_value = round(
temp + 0.348 * e_value - 0.7 * wind - 4.25, 1
)
_LOGGER.debug(
"New sensor state is %s %s",
self._attr_native_value,
Expand Down

0 comments on commit 7431213

Please sign in to comment.