Skip to content

Commit

Permalink
Merge pull request #80 from basbruss/dev
Browse files Browse the repository at this point in the history
Fix bug get_safe_state
  • Loading branch information
basbruss authored Mar 23, 2024
2 parents 2f48fb5 + 90f650f commit e263a2b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
12 changes: 9 additions & 3 deletions custom_components/adaptive_cover/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,21 @@ def outside_temperature(self):
if self.weather_entity:
temp = state_attr(self.hass, self.weather_entity, "temperature")
if self.outside_entity:
temp = get_safe_state(self.outside_entity, self.hass)
temp = get_safe_state(
self.hass,
self.outside_entity,
)
return temp

@property
def inside_temperature(self):
"""Get inside temp from entity."""
if self.temp_entity is not None:
if get_domain(self.temp_entity) != "climate":
temp = get_safe_state(self.temp_entity, self.hass)
temp = get_safe_state(
self.hass,
self.temp_entity,
)
else:
temp = state_attr(self.hass, self.temp_entity, "current_temperature")
return temp
Expand Down Expand Up @@ -217,7 +223,7 @@ def is_sunny(self) -> bool:
"""Check if condition can contain radiation in winter."""
weather_state = None
if self.weather_entity is not None:
weather_state = get_safe_state(self.weather_entity, self.hass)
weather_state = get_safe_state(self.hass, self.weather_entity)
if self.weather_condition is not None:
return weather_state in self.weather_condition
return True
Expand Down
4 changes: 0 additions & 4 deletions custom_components/adaptive_cover/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ async def _async_update_data(self) -> AdaptiveCoverData:
],
"entity_id": self.config_entry.options.get(CONF_ENTITIES),
"cover_type": self._cover_type,
"outside": self.config_entry.options.get(CONF_OUTSIDETEMP_ENTITY),
"outside_temp": climate_data.outside_temperature,
"current_temp": climate_data.get_current_temperature,
"toggle": climate_data.temp_switch,
},
)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/adaptive_cover/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from homeassistant.core import HomeAssistant, split_entity_id


def get_safe_state(entity_id: str, hass: HomeAssistant):
def get_safe_state(hass: HomeAssistant, entity_id: str):
"""Get a safe state value if not available."""
state = hass.states.get(entity_id)
if not state or state.state in ["unknown", "unavailable"]:
Expand Down

0 comments on commit e263a2b

Please sign in to comment.