Skip to content

Commit

Permalink
chore: improves logging
Browse files Browse the repository at this point in the history
Fixes #268
  • Loading branch information
= authored and swingerman committed Sep 4, 2024
1 parent e4be12d commit 0c45e9e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 30 deletions.
30 changes: 17 additions & 13 deletions custom_components/dual_smart_thermostat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ async def async_set_hvac_mode(

if hvac_mode == HVACMode.OFF:
self._last_hvac_mode = self.hvac_device.hvac_mode
_LOGGER.debug(
_LOGGER.info(
"Turning off with saving last hvac mode: %s", self._last_hvac_mode
)

Expand Down Expand Up @@ -882,9 +882,12 @@ async def async_set_temperature(self, **kwargs) -> None:
temp_low = kwargs.get(ATTR_TARGET_TEMP_LOW)
temp_high = kwargs.get(ATTR_TARGET_TEMP_HIGH)

_LOGGER.debug("Setting temperature: %s", temperature)
_LOGGER.debug("Setting temperature low: %s", temp_low)
_LOGGER.debug("Setting temperature high: %s", temp_high)
_LOGGER.info(
"Setting temperatures. Temp: %s, Low: %s, High: %s",
temperature,
temp_low,
temp_high,
)

temperatures = TargetTemperatures(temperature, temp_high, temp_low)

Expand All @@ -901,7 +904,8 @@ async def async_set_temperature(self, **kwargs) -> None:

async def async_set_humidity(self, humidity: float) -> None:
"""Set new target humidity."""
_LOGGER.debug("Setting humidity: %s", humidity)
_LOGGER.info("Setting humidity: %s", humidity)

self.environment.target_humidity = humidity
self._target_humidity = self.environment.target_humidity

Expand Down Expand Up @@ -981,7 +985,7 @@ async def _async_sensor_not_responding(self, now: datetime | None = None) -> Non
"""Handle sensor stale event."""

state = self.hass.states.get(self.sensor_entity_id)
_LOGGER.debug(
_LOGGER.info(
"Sensor has not been updated for %s",
now - state.last_updated if now and state else "---",
)
Expand All @@ -997,7 +1001,7 @@ async def _async_humidity_sensor_not_responding(
"""Handle humidity sensor stale event."""

state = self.hass.states.get(self.sensor_humidity_entity_id)
_LOGGER.debug(
_LOGGER.info(
"HUmidity sensor has not been updated for %s",
now - state.last_updated if now and state else "---",
)
Expand Down Expand Up @@ -1149,7 +1153,7 @@ async def _async_opening_changed(self, event: Event[EventStateChangedData]) -> N
async def _async_control_climate(self, time=None, force=False) -> None:
"""Control the climate device based on config."""

_LOGGER.info("_async_control_climate, time %s, force %s", time, force)
_LOGGER.info("Attempting to control climate, time %s, force %s", time, force)

async with self._temp_lock:
await self.hvac_device.async_control_hvac(time, force)
Expand All @@ -1161,7 +1165,7 @@ async def _async_control_climate(self, time=None, force=False) -> None:
self._hvac_action_reason = self.hvac_device.HVACActionReason

async def _async_control_climate_forced(self, time=None) -> None:
_LOGGER.debug("_async_control_climate_forced, time %s", time)
_LOGGER.info("Attempting to forcefully control climate, time %s", time)
await self._async_control_climate(force=True, time=time)

self.async_write_ha_state()
Expand All @@ -1186,7 +1190,7 @@ def _async_switch_changed(
self, old_state: State | None, new_state: State | None
) -> None:
"""Handle heater switch state changes."""
_LOGGER.debug(
_LOGGER.info(
"Switch changed: old_state: %s, new_state: %s", old_state, new_state
)
if new_state is None:
Expand All @@ -1203,7 +1207,7 @@ def _is_device_active(self) -> bool:

async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode."""
_LOGGER.debug(
_LOGGER.info(
"Climate Setting preset mode: %s, is_range_mode: %s",
preset_mode,
self.features.is_range_mode,
Expand Down Expand Up @@ -1241,7 +1245,7 @@ async def async_set_preset_mode(self, preset_mode: str) -> None:
def _set_hvac_action_reason(self, *args) -> None:
"""My first service."""
reason = args[0]
_LOGGER.debug("Received HVACActionReasonExternal data %s", reason)
_LOGGER.info("Received HVACActionReasonExternal data %s", reason)

# make sure its a valid reason
if reason not in HVACActionReasonExternal:
Expand All @@ -1254,7 +1258,7 @@ def _set_hvac_action_reason(self, *args) -> None:

async def async_turn_on(self) -> None:
"""Turn on the device."""
_LOGGER.debug("Turning on with last hvac mode: %s", self._last_hvac_mode)
_LOGGER.info("Turning on with last hvac mode: %s", self._last_hvac_mode)
if self._last_hvac_mode is not None and self._last_hvac_mode != HVACMode.OFF:
on_hvac_mode = self._last_hvac_mode
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def is_active(self) -> bool:
"""If the toggleable hvac device is currently active."""
on_state = STATE_OPEN if self._is_valve else STATE_ON

_LOGGER.debug(
_LOGGER.info(
"Checking if device is active: %s, on_state: %s",
self.entity_id,
on_state,
Expand Down Expand Up @@ -134,13 +134,16 @@ async def async_control_device_when_on(
) -> None:
"""Check if we need to turn heating on or off when theheater is on."""

_LOGGER.debug("%s _async_control_device_when_on", self.__class__.__name__)
_LOGGER.info("%s Controlling hvac while on", self.__class__.__name__)
_LOGGER.debug("below_env_attr: %s", strategy.hvac_goal_reached)
_LOGGER.debug("any_opening_open: %s", any_opening_open)
_LOGGER.debug("hvac_goal_reached: %s", strategy.hvac_goal_reached)

if strategy.hvac_goal_reached or any_opening_open:
_LOGGER.debug("Turning off entity %s", self.entity_id)
_LOGGER.info(
"Turning off entity due to hvac goal reached or opening is open %s",
self.entity_id,
)

await self.async_turn_off_callback()

Expand All @@ -153,7 +156,7 @@ async def async_control_device_when_on(

elif time is not None and not any_opening_open:
# The time argument is passed only in keep-alive case
_LOGGER.debug(
_LOGGER.info(
"Keep-alive - Turning on entity (from active) %s",
self.entity_id,
)
Expand All @@ -169,20 +172,23 @@ async def async_control_device_when_off(
time=None,
) -> None:
"""Check if we need to turn heating on or off when the heater is off."""
_LOGGER.debug("%s _async_control_device_when_off", self.__class__.__name__)
_LOGGER.info("%s Controlling hvac while off", self.__class__.__name__)
_LOGGER.debug("above_env_attr: %s", strategy.hvac_goal_reached)
_LOGGER.debug("below_env_attr: %s", strategy.hvac_goal_not_reached)
_LOGGER.debug("any_opening_open: %s", any_opening_open)
_LOGGER.debug("is_active: %s", True)
_LOGGER.debug("time: %s", time)

if strategy.hvac_goal_not_reached and not any_opening_open:
_LOGGER.debug("Turning on entity (from inactive) %s", self.entity_id)
_LOGGER.info(
"Turning on entity (from inactive) due to hvac goal is not reached %s",
self.entity_id,
)
await self.async_turn_on_callback()
self._hvac_action_reason = strategy.goal_not_reached_reason()
elif time is not None or any_opening_open:
# The time argument is passed only in keep-alive case
_LOGGER.debug("Keep-alive - Turning off entity %s", self.entity_id)
_LOGGER.info("Keep-alive - Turning off entity %s", self.entity_id)
await self.async_turn_off_callback()

if any_opening_open:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ async def async_control_device_when_on(
time=None,
) -> None:
"""Check if we need to turn heating on or off when theheater is on."""

_LOGGER.info("%s Controlling hvac while on", self.__class__.__name__)

too_hot = strategy.hvac_goal_reached
is_floor_hot = self._environment.is_floor_hot
is_floor_cold = self._environment.is_floor_cold
Expand Down Expand Up @@ -89,7 +92,7 @@ async def async_control_device_when_off(
time=None,
) -> None:
"""Check if we need to turn heating on or off when the heater is off."""
_LOGGER.debug("%s _async_control_device_when_off", self.__class__.__name__)
_LOGGER.info("%s Controlling hvac while off", self.__class__.__name__)

too_cold = strategy.hvac_goal_not_reached
_LOGGER.debug("too_cold: %s", strategy.hvac_goal_reached)
Expand All @@ -98,7 +101,7 @@ async def async_control_device_when_off(
is_floor_cold = self._environment.is_floor_cold

if (too_cold and not any_opening_open and not is_floor_hot) or is_floor_cold:
_LOGGER.debug("Turning on heater (from inactive) %s", self.entity_id)
_LOGGER.info("Turning on heater (from inactive) %s", self.entity_id)

await self.async_turn_on_callback()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def _async_fan_hot_tolerance_on_changed(

new_state = data["new_state"]

_LOGGER.debug("Fan hot tolerance on changed: %s", new_state)
_LOGGER.info("Fan hot tolerance on changed: %s", new_state)

if new_state is None or new_state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN):
self._fan_hot_tolerance_on = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def on_entity_state_changed(self, entity_id: str, new_state: State) -> None:

def _apply_heat_pump_cooling_state(self, state: State = None) -> None:
"""Applies the state of the heat pump cooling entity to the device."""
_LOGGER.debug("Applying heat pump cooling state, state: %s", state)
_LOGGER.info("Applying heat pump cooling state, state: %s", state)
entity_id = self.features.heat_pump_cooling_entity_id
entity_state = state or self.hass.states.get(entity_id)

Expand Down Expand Up @@ -204,7 +204,7 @@ def _change_hvac_modes(self, heat_pump_is_cooling: bool) -> None:

def _change_hvac_mode(self, heat_pump_is_cooling: bool) -> None:
"""Changes the HVAC mode based on the heat pump's current mode."""
_LOGGER.debug(
_LOGGER.info(
"Changing hvac mode based on heat pump mode, heat_pump_is_cooling: %s, hvac_mode: %s, hvac_modes: %s",
heat_pump_is_cooling,
self.hvac_mode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async def async_control_devices_forced(self, time=None) -> None:

async def _async_control_devices_when_off(self, time=None) -> None:
"""Check if we need to turn heating on or off when the heater is off."""
_LOGGER.debug("%s _async_control_devices_when_off", self.__class__.__name__)
_LOGGER.info("%s Controlling hvac while off", self.__class__.__name__)

too_cold = self.environment.is_too_cold(self._target_env_attr)
is_floor_hot = self.environment.is_floor_hot
Expand Down Expand Up @@ -136,15 +136,15 @@ async def _async_handle_aux_heater_havent_run_today(self) -> None:

async def _async_control_devices_when_on(self, time=None) -> None:
"""Check if we need to turn heating on or off when the heater is off."""
_LOGGER.debug("%s _async_control_devices_when_on", self.__class__.__name__)
_LOGGER.info("%s Controlling hvac while on", self.__class__.__name__)

too_hot = self.environment.is_too_hot(self._target_env_attr)
is_floor_hot = self.environment.is_floor_hot
is_floor_cold = self.environment.is_floor_cold
any_opening_open = self.openings.any_opening_open(self.hvac_mode)
first_stage_timed_out = self._first_stage_heating_timed_out()

_LOGGER.info(
_LOGGER.debug(
"too_hot: %s, is_floor_hot: %s, is_floor_cold: %s, any_opening_open: %s, time: %s",
too_hot,
is_floor_hot,
Expand All @@ -157,8 +157,8 @@ async def _async_control_devices_when_on(self, time=None) -> None:
"_first_stage_heating_timed_out: %s",
first_stage_timed_out,
)
_LOGGER.info("aux_heater_timeout: %s", self._aux_heater_timeout)
_LOGGER.info(
_LOGGER.debug("aux_heater_timeout: %s", self._aux_heater_timeout)
_LOGGER.debug(
"aux_heater_device.is_active: %s", self.aux_heater_device.is_active
)

Expand Down

0 comments on commit 0c45e9e

Please sign in to comment.