Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrozdnovak committed Jan 7, 2024
1 parent 020fc0d commit 5c3e22c
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions custom_components/temperature_feels_like/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
)
from homeassistant.components.group import expand_entity_ids
from homeassistant.components.number import NumberDeviceClass
from homeassistant.components.sensor import SensorEntity, SensorStateClass, SensorDeviceClass
from homeassistant.components.sensor import (
SensorEntity,
SensorStateClass,
SensorDeviceClass,
)
from homeassistant.components.weather import (
ATTR_WEATHER_HUMIDITY,
ATTR_WEATHER_TEMPERATURE,
Expand Down Expand Up @@ -159,7 +163,9 @@ 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 == SensorDeviceClass.TEMPERATURE
Expand Down Expand Up @@ -194,11 +200,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 @@ -237,7 +247,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 @@ -297,7 +309,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 @@ -313,7 +327,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 5c3e22c

Please sign in to comment.