1 """GoodWe PV inverter selection settings entities."""
3 from collections.abc
import Awaitable, Callable
4 from dataclasses
import dataclass
5 from datetime
import datetime
8 from goodwe
import Inverter, InverterError
17 from .const
import DOMAIN, KEY_DEVICE_INFO, KEY_INVERTER
19 _LOGGER = logging.getLogger(__name__)
22 @dataclass(frozen=True, kw_only=True)
24 """Class describing Goodwe button entities."""
26 action: Callable[[Inverter], Awaitable[
None]]
30 key=
"synchronize_clock",
31 translation_key=
"synchronize_clock",
32 entity_category=EntityCategory.CONFIG,
33 action=
lambda inv: inv.write_setting(
"time", datetime.now()),
39 config_entry: ConfigEntry,
40 async_add_entities: AddEntitiesCallback,
42 """Set up the inverter button entities from a config entry."""
43 inverter = hass.data[DOMAIN][config_entry.entry_id][KEY_INVERTER]
44 device_info = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE_INFO]
48 await inverter.read_setting(
"time")
49 except (InverterError, ValueError):
51 _LOGGER.debug(
"Could not read inverter current clock time")
59 """Entity representing the inverter clock synchronization button."""
61 _attr_should_poll =
False
62 _attr_has_entity_name =
True
63 entity_description: GoodweButtonEntityDescription
67 device_info: DeviceInfo,
68 description: GoodweButtonEntityDescription,
71 """Initialize the inverter operation mode setting entity."""
73 self.
_attr_unique_id_attr_unique_id = f
"{description.key}-{inverter.serial_number}"
75 self._inverter: Inverter = inverter
78 """Triggers the button press service."""