mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Fix Goodwe spinlock (#80624)
* fix spinlock * Add debug log * fix styling
This commit is contained in:
parent
8dc0846d98
commit
8974657ba9
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
import logging
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
from goodwe import Inverter, Sensor, SensorKind
|
from goodwe import Inverter, Sensor, SensorKind
|
||||||
@ -36,6 +37,8 @@ import homeassistant.util.dt as dt_util
|
|||||||
|
|
||||||
from .const import DOMAIN, KEY_COORDINATOR, KEY_DEVICE_INFO, KEY_INVERTER
|
from .const import DOMAIN, KEY_COORDINATOR, KEY_DEVICE_INFO, KEY_INVERTER
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Sensor name of battery SoC
|
# Sensor name of battery SoC
|
||||||
BATTERY_SOC = "battery_soc"
|
BATTERY_SOC = "battery_soc"
|
||||||
|
|
||||||
@ -209,7 +212,10 @@ class InverterSensor(CoordinatorEntity, SensorEntity):
|
|||||||
self._previous_value = 0
|
self._previous_value = 0
|
||||||
self.coordinator.data[self._sensor.id_] = 0
|
self.coordinator.data[self._sensor.id_] = 0
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
next_midnight = dt_util.start_of_local_day(dt_util.utcnow() + timedelta(days=1))
|
_LOGGER.debug("Goodwe reset %s to 0", self.name)
|
||||||
|
next_midnight = dt_util.start_of_local_day(
|
||||||
|
dt_util.now() + timedelta(days=1, minutes=1)
|
||||||
|
)
|
||||||
self._stop_reset = async_track_point_in_time(
|
self._stop_reset = async_track_point_in_time(
|
||||||
self.hass, self.async_reset, next_midnight
|
self.hass, self.async_reset, next_midnight
|
||||||
)
|
)
|
||||||
@ -218,7 +224,7 @@ class InverterSensor(CoordinatorEntity, SensorEntity):
|
|||||||
"""Schedule reset task at midnight."""
|
"""Schedule reset task at midnight."""
|
||||||
if self._sensor.id_ in DAILY_RESET:
|
if self._sensor.id_ in DAILY_RESET:
|
||||||
next_midnight = dt_util.start_of_local_day(
|
next_midnight = dt_util.start_of_local_day(
|
||||||
dt_util.utcnow() + timedelta(days=1)
|
dt_util.now() + timedelta(days=1)
|
||||||
)
|
)
|
||||||
self._stop_reset = async_track_point_in_time(
|
self._stop_reset = async_track_point_in_time(
|
||||||
self.hass, self.async_reset, next_midnight
|
self.hass, self.async_reset, next_midnight
|
||||||
|
Loading…
x
Reference in New Issue
Block a user