Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
basbruss committed Nov 28, 2023
1 parent be4a263 commit 80b234f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
31 changes: 16 additions & 15 deletions custom_components/adaptive_cover/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__( # noqa: D107
self.fov_right = fov_right
self.win_azi = win_azi
self.h_def = h_def
self.sun_data = SunData(self.hass, timezone)
self.sun_data = SunData(self.timezone, self.hass)

def solar_times(self):
"""Determine start/end times."""
Expand Down Expand Up @@ -172,21 +172,21 @@ def __init__(
@property
def is_presence(self):
"""Checks if people are present."""
domain = get_domain(self.presence_entity)
# set to true if no sensor is defined
if self.presence_entity is None:
return True
if domain == "device_tracker":
return str(self.presence) == "home"
if domain == "zone":
return int(self.presence) > 0
if domain == "binary_sensor":
return bool(self.presence)
if self.presence is not None:
domain = get_domain(self.presence_entity)
if domain == "device_tracker":
return self.presence == "home"
if domain == "zone":
return int(self.presence) > 0
if domain == "binary_sensor":
return bool(self.presence)
return True

def climate_state(self):
"""Adjust state to environment needs."""
# glare does not matter
if self.is_presence is False:
if self.is_presence is False and self.temp is not None:
# allow maximum solar radiation
if self.temp < self.low_point:
return 100
Expand Down Expand Up @@ -458,8 +458,9 @@ def control_method_tilt_bi(self):

def climate_state(self):
"""Add tilt specific controls."""
if self.mode == "mode1":
self.control_method_tilt_single()
if self.mode == "mode2":
return self.control_method_tilt_bi()
if self.temp is not None:
if self.mode == "mode1":
self.control_method_tilt_single()
if self.mode == "mode2":
return self.control_method_tilt_bi()
return self.basic_state()
21 changes: 12 additions & 9 deletions custom_components/adaptive_cover/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ def native_value(self) -> str | None:
@property
def extra_state_attributes(self) -> Mapping[str, Any] | None: # noqa: D102
dict_attributes = {
"mode": self.config_entry.data.get(CONF_MODE, "basic"),
"azimuth_window": self.config_entry.options[CONF_AZIMUTH],
"default_height": self.config_entry.options[CONF_DEFAULT_HEIGHT],
# "field_of_view": self._cover_data.fov,
"field_of_view": self._cover_data.fov,
# 'start_time': self._cover_data.start,
# 'end_time': self._cover_data.end,
"entity_id": self.config_entry.options[CONF_ENTITIES],
Expand Down Expand Up @@ -186,21 +187,21 @@ def __init__( # noqa: D107
self.awn_angle = 0
self.start = None
self.end = None
self.fov = None
self.sunset_pos = 0
self.sunset_off = 0
self.slat_distance = 2
self.depth = 3
self.tilt_mode = "mode2"
self.fov_left = self.config_entry.options[CONF_FOV_LEFT]
self.fov_right = self.config_entry.options[CONF_FOV_RIGHT]
self.fov = [self.fov_left, self.fov_right]
self.win_azi = 180
self.inverse_state = False
self._state = None
self.current_temp = (None,)
self.temp_low = (None,)
self.temp_high = (None,)
self.presence = (None,)
self.current_temp = None
self.temp_low = None
self.temp_high = None
self.presence = None
self.presence_entity = None
self.climate_state = None

Expand All @@ -214,6 +215,7 @@ def update(self):
self.timezone = self.hass.config.time_zone
self.fov_left = self.config_entry.options[CONF_FOV_LEFT]
self.fov_right = self.config_entry.options[CONF_FOV_RIGHT]
self.fov = [self.fov_left, self.fov_right]
self.win_azi = self.config_entry.options[CONF_AZIMUTH]
self.h_def = self.config_entry.options[CONF_DEFAULT_HEIGHT]
self._mode = self.config_entry.data.get(CONF_MODE, "basic")
Expand Down Expand Up @@ -309,15 +311,16 @@ def update_climate(self):
self.temp_high = self.config_entry.options[CONF_TEMP_HIGH]
self.temp_entity = self.config_entry.options["temp_entity"]
self.presence_entity = self.config_entry.options["presence_entity"]
self.presence = None
if get_domain(self.temp_entity) == "climate":
self.current_temp = self.hass.states.get(self.temp_entity).attributes[
"current_temperature"
]
else:
self.current_temp = self.hass.states.get(self.temp_entity)
self.presence = None
self.current_temp = self.hass.states.get("sun.sun").state or None

if self.presence_entity is not None:
self.presence = self.hass.states.get(self.presence_entity)
self.presence = self.hass.states.get("sun.sun").state or None

@property
def state(self):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/adaptive_cover/sun.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class SunData:
"""Access local sun data."""

def __init__(self, hass: HomeAssistant, timezone) -> None: # noqa: D107
def __init__(self, timezone, hass: HomeAssistant) -> None: # noqa: D107
self.hass = hass
location, elevation = get_astral_location(self.hass)
self.location = location # astral.location.Location
Expand Down

0 comments on commit 80b234f

Please sign in to comment.