diff --git a/custom_components/solarman/__init__.py b/custom_components/solarman/__init__.py index 5637a0f..40e4748 100644 --- a/custom_components/solarman/__init__.py +++ b/custom_components/solarman/__init__.py @@ -25,7 +25,7 @@ CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN) -async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: +async def async_setup(hass: HomeAssistant, _: ConfigType) -> bool: _LOGGER.debug(f"async_setup") async_register(hass) @@ -76,15 +76,15 @@ async def async_update_listener(hass: HomeAssistant, config_entry: ConfigEntry) return True -async def async_unload_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: - _LOGGER.debug(f"async_unload_entry({config.as_dict()})") +async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: + _LOGGER.debug(f"async_unload_entry({config_entry.as_dict()})") # Forward setup # _LOGGER.debug(f"async_setup: hass.config_entries.async_unload_platforms: {PLATFORMS}") - if unload_ok := await hass.config_entries.async_unload_platforms(config, PLATFORMS): - _ = hass.data[DOMAIN].pop(config.entry_id) + if unload_ok := await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS): + _ = hass.data[DOMAIN].pop(config_entry.entry_id) return unload_ok diff --git a/custom_components/solarman/binary_sensor.py b/custom_components/solarman/binary_sensor.py index 861604c..b394bc2 100644 --- a/custom_components/solarman/binary_sensor.py +++ b/custom_components/solarman/binary_sensor.py @@ -27,11 +27,10 @@ def _create_entity(coordinator, description): return SolarmanBinarySensorEntity(coordinator, description) -async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool: - _LOGGER.debug(f"async_setup_entry: {config.options}") +async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool: + _LOGGER.debug(f"async_setup_entry: {config_entry.options}") - coordinator = hass.data[DOMAIN][config.entry_id] - descriptions = coordinator.inverter.get_entity_descriptions() + coordinator, descriptions = get_coordinator(hass, config_entry.entry_id) _LOGGER.debug(f"async_setup_entry: async_add_entities") @@ -39,8 +38,8 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_ return True -async def async_unload_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: - _LOGGER.debug(f"async_unload_entry: {config.options}") +async def async_unload_entry(_: HomeAssistant, config_entry: ConfigEntry) -> bool: + _LOGGER.debug(f"async_unload_entry: {config_entry.options}") return True diff --git a/custom_components/solarman/button.py b/custom_components/solarman/button.py index 1ba8319..4ec869e 100644 --- a/custom_components/solarman/button.py +++ b/custom_components/solarman/button.py @@ -19,11 +19,10 @@ _PLATFORM = get_current_file_name(__name__) -async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool: - _LOGGER.debug(f"async_setup_entry: {config.options}") +async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool: + _LOGGER.debug(f"async_setup_entry: {config_entry.options}") - coordinator = hass.data[DOMAIN][config.entry_id] - descriptions = coordinator.inverter.get_entity_descriptions() + coordinator, descriptions = get_coordinator(hass, config_entry.entry_id) _LOGGER.debug(f"async_setup_entry: async_add_entities") @@ -31,8 +30,8 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_ return True -async def async_unload_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: - _LOGGER.debug(f"async_unload_entry: {config.options}") +async def async_unload_entry(_: HomeAssistant, config_entry: ConfigEntry) -> bool: + _LOGGER.debug(f"async_unload_entry: {config_entry.options}") return True diff --git a/custom_components/solarman/common.py b/custom_components/solarman/common.py index 41828a0..7647c0a 100644 --- a/custom_components/solarman/common.py +++ b/custom_components/solarman/common.py @@ -11,6 +11,7 @@ from typing import Any +from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo, format_mac from .const import * @@ -36,6 +37,10 @@ def execute_async(x): loop = asyncio.get_event_loop() return loop.run_until_complete(x) +def get_coordinator(hass: HomeAssistant, entry_id: str): + coordinator = hass.data[DOMAIN][entry_id] + return coordinator, coordinator.inverter.get_entity_descriptions() + def to_dict(*keys: list): return {k: k for k in keys} diff --git a/custom_components/solarman/datetime.py b/custom_components/solarman/datetime.py index fb398b4..e422831 100644 --- a/custom_components/solarman/datetime.py +++ b/custom_components/solarman/datetime.py @@ -19,11 +19,10 @@ _PLATFORM = get_current_file_name(__name__) -async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool: - _LOGGER.debug(f"async_setup_entry: {config.options}") +async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool: + _LOGGER.debug(f"async_setup_entry: {config_entry.options}") - coordinator = hass.data[DOMAIN][config.entry_id] - descriptions = coordinator.inverter.get_entity_descriptions() + coordinator, descriptions = get_coordinator(hass, config_entry.entry_id) _LOGGER.debug(f"async_setup_entry: async_add_entities") @@ -31,8 +30,8 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_ return True -async def async_unload_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: - _LOGGER.debug(f"async_unload_entry: {config.options}") +async def async_unload_entry(_: HomeAssistant, config_entry: ConfigEntry) -> bool: + _LOGGER.debug(f"async_unload_entry: {config_entry.options}") return True diff --git a/custom_components/solarman/number.py b/custom_components/solarman/number.py index 33f9b3d..6ed0b54 100644 --- a/custom_components/solarman/number.py +++ b/custom_components/solarman/number.py @@ -18,11 +18,10 @@ _PLATFORM = get_current_file_name(__name__) -async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool: - _LOGGER.debug(f"async_setup_entry: {config.options}") +async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool: + _LOGGER.debug(f"async_setup_entry: {config_entry.options}") - coordinator = hass.data[DOMAIN][config.entry_id] - descriptions = coordinator.inverter.get_entity_descriptions() + coordinator, descriptions = get_coordinator(hass, config_entry.entry_id) _LOGGER.debug(f"async_setup_entry: async_add_entities") @@ -30,8 +29,8 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_ return True -async def async_unload_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: - _LOGGER.debug(f"async_unload_entry: {config.options}") +async def async_unload_entry(_: HomeAssistant, config_entry: ConfigEntry) -> bool: + _LOGGER.debug(f"async_unload_entry: {config_entry.options}") return True diff --git a/custom_components/solarman/select.py b/custom_components/solarman/select.py index 8459252..21114aa 100644 --- a/custom_components/solarman/select.py +++ b/custom_components/solarman/select.py @@ -18,11 +18,10 @@ _PLATFORM = get_current_file_name(__name__) -async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool: - _LOGGER.debug(f"async_setup_entry: {config.options}") +async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool: + _LOGGER.debug(f"async_setup_entry: {config_entry.options}") - coordinator = hass.data[DOMAIN][config.entry_id] - descriptions = coordinator.inverter.get_entity_descriptions() + coordinator, descriptions = get_coordinator(hass, config_entry.entry_id) _LOGGER.debug(f"async_setup_entry: async_add_entities") @@ -30,8 +29,8 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_ return True -async def async_unload_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: - _LOGGER.debug(f"async_unload_entry: {config.options}") +async def async_unload_entry(_: HomeAssistant, config_entry: ConfigEntry) -> bool: + _LOGGER.debug(f"async_unload_entry: {config_entry.options}") return True diff --git a/custom_components/solarman/sensor.py b/custom_components/solarman/sensor.py index 1026e69..1ac4b3d 100644 --- a/custom_components/solarman/sensor.py +++ b/custom_components/solarman/sensor.py @@ -48,20 +48,19 @@ def _create_entity(coordinator, description, options): return SolarmanSensor(coordinator, description) -async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool: - _LOGGER.debug(f"async_setup_entry: {config.options}") +async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool: + _LOGGER.debug(f"async_setup_entry: {config_entry.options}") - coordinator = hass.data[DOMAIN][config.entry_id] - descriptions = coordinator.inverter.get_entity_descriptions() + coordinator, descriptions = get_coordinator(hass, config_entry.entry_id) _LOGGER.debug(f"async_setup_entry: async_add_entities") - async_add_entities(create_entity(lambda x: _create_entity(coordinator, x, config.options), d) for d in descriptions if (is_platform(d, _PLATFORM) and not "configurable" in d)) + async_add_entities(create_entity(lambda x: _create_entity(coordinator, x, config_entry.options), d) for d in descriptions if (is_platform(d, _PLATFORM) and not "configurable" in d)) return True -async def async_unload_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: - _LOGGER.debug(f"async_unload_entry: {config.options}") +async def async_unload_entry(_: HomeAssistant, config_entry: ConfigEntry) -> bool: + _LOGGER.debug(f"async_unload_entry: {config_entry.options}") return True diff --git a/custom_components/solarman/switch.py b/custom_components/solarman/switch.py index 3ef7586..eb3ba00 100644 --- a/custom_components/solarman/switch.py +++ b/custom_components/solarman/switch.py @@ -19,11 +19,10 @@ _PLATFORM = get_current_file_name(__name__) -async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool: - _LOGGER.debug(f"async_setup_entry: {config.options}") +async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool: + _LOGGER.debug(f"async_setup_entry: {config_entry.options}") - coordinator = hass.data[DOMAIN][config.entry_id] - descriptions = coordinator.inverter.get_entity_descriptions() + coordinator, descriptions = get_coordinator(hass, config_entry.entry_id) _LOGGER.debug(f"async_setup_entry: async_add_entities") @@ -31,8 +30,8 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_ return True -async def async_unload_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: - _LOGGER.debug(f"async_unload_entry: {config.options}") +async def async_unload_entry(_: HomeAssistant, config_entry: ConfigEntry) -> bool: + _LOGGER.debug(f"async_unload_entry: {config_entry.options}") return True diff --git a/custom_components/solarman/time.py b/custom_components/solarman/time.py index f9c2138..204f101 100644 --- a/custom_components/solarman/time.py +++ b/custom_components/solarman/time.py @@ -18,11 +18,10 @@ _PLATFORM = get_current_file_name(__name__) -async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool: - _LOGGER.debug(f"async_setup_entry: {config.options}") +async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool: + _LOGGER.debug(f"async_setup_entry: {config_entry.options}") - coordinator = hass.data[DOMAIN][config.entry_id] - descriptions = coordinator.inverter.get_entity_descriptions() + coordinator, descriptions = get_coordinator(hass, config_entry.entry_id) _LOGGER.debug(f"async_setup_entry: async_add_entities") @@ -30,8 +29,8 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_ return True -async def async_unload_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: - _LOGGER.debug(f"async_unload_entry: {config.options}") +async def async_unload_entry(_: HomeAssistant, config_entry: ConfigEntry) -> bool: + _LOGGER.debug(f"async_unload_entry: {config_entry.options}") return True