Skip to content

Commit

Permalink
Make linters happy by updating imports, docstrings
Browse files Browse the repository at this point in the history
and some logic
  • Loading branch information
wlcrs committed Jul 17, 2023
1 parent 7ec4d7d commit f58daf3
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 152 deletions.
5 changes: 1 addition & 4 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"Consider enabling elevated permissions to get more optimizer data",
exc_info=exception,
)
optimizers_device_infos = None
optimizers_device_infos = {}
except Exception as exc: # pylint: disable=broad-except
_LOGGER.exception(
"Cannot create optimizer sensor entities due to an unexpected error",
Expand Down Expand Up @@ -319,7 +319,6 @@ async def _create_update_coordinator(
device_infos: HuaweiInverterBridgeDeviceInfos,
update_interval,
):

coordinator = HuaweiSolarUpdateCoordinator(
hass,
_LOGGER,
Expand Down Expand Up @@ -377,7 +376,6 @@ async def _create_optimizer_update_coordinator(
optimizer_device_infos: dict[int, DeviceInfo],
update_interval,
):

coordinator = HuaweiSolarOptimizerUpdateCoordinator(
hass,
_LOGGER,
Expand Down Expand Up @@ -434,7 +432,6 @@ async def _create_configuration_update_coordinator(
device_infos: HuaweiInverterBridgeDeviceInfos,
update_interval,
):

coordinator = HuaweiSolarConfigurationUpdateCoordinator(
hass,
_LOGGER,
Expand Down
10 changes: 3 additions & 7 deletions config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
ConnectionException,
HuaweiSolarBridge,
HuaweiSolarException,
InvalidCredentials,
ReadException,
InvalidCredentials
)

from .const import (
Expand Down Expand Up @@ -226,15 +226,14 @@ async def async_step_user(
async def async_step_setup_serial(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handles connection parameters when using ModbusRTU."""
"""Handle connection parameters when using ModbusRTU."""

# Parameter configuration is always possible over serial connection
self._enable_parameter_configuration = True

errors = {}

if user_input is not None:

user_selection = user_input[CONF_PORT]
if user_selection == CONF_MANUAL_PATH:
self._slave_ids = user_input[CONF_SLAVE_IDS]
Expand All @@ -251,7 +250,6 @@ async def async_step_setup_serial(
except ValueError:
errors["base"] = "invalid_slave_ids"
else:

try:
info = await validate_serial_setup(user_input)

Expand Down Expand Up @@ -317,7 +315,6 @@ async def async_step_setup_serial_manual_path(
errors = {}

if user_input is not None:

try:
user_input[CONF_SLAVE_IDS] = list(
map(int, user_input[CONF_SLAVE_IDS].split(","))
Expand Down Expand Up @@ -369,7 +366,7 @@ async def async_step_setup_serial_manual_path(
async def async_step_setup_network(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handles connection parameters when using ModbusTCP."""
"""Handle connection parameters when using ModbusTCP."""

errors = {}

Expand All @@ -381,7 +378,6 @@ async def async_step_setup_network(
except ValueError:
errors["base"] = "invalid_slave_ids"
else:

try:
info = await validate_network_setup(user_input)

Expand Down
7 changes: 3 additions & 4 deletions diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
from huawei_solar import HuaweiSolarBridge

from . import (
HuaweiSolarUpdateCoordinator,
HuaweiSolarConfigurationUpdateCoordinator,
HuaweiSolarOptimizerUpdateCoordinator,
HuaweiSolarUpdateCoordinator,
)
from .const import (
DATA_UPDATE_COORDINATORS,
DOMAIN,
DATA_CONFIGURATION_UPDATE_COORDINATORS,
DATA_OPTIMIZER_UPDATE_COORDINATORS,
DATA_UPDATE_COORDINATORS,
DOMAIN,
)

TO_REDACT = {CONF_PASSWORD}
Expand Down Expand Up @@ -69,7 +69,6 @@ async def async_get_config_entry_diagnostics(


async def _build_bridge_diagnostics_info(bridge: HuaweiSolarBridge) -> dict[str, Any]:

diagnostics_data = {
"model_name": bridge.model_name,
"pv_string_count": bridge.pv_string_count,
Expand Down
10 changes: 5 additions & 5 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Huawei Solar",
"content_in_root": true,
"render_readme": true,
"homeassistant": "2023.3.7"
}
"name": "Huawei Solar",
"content_in_root": true,
"render_readme": true,
"homeassistant": "2023.3.7",
}
29 changes: 11 additions & 18 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
{
"domain": "huawei_solar",
"name": "Huawei Solar",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/huawei_solar",
"issue_tracker": "https://github.com/wlcrs/huawei_solar/issues",
"requirements": [
"huawei-solar==2.2.8b2"
],
"codeowners": [
"@wlcrs"
],
"iot_class": "local_polling",
"version": "1.2.6b8",
"loggers": [
"huawei_solar",
"pymodbus"
]
}
"domain": "huawei_solar",
"name": "Huawei Solar",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/huawei_solar",
"issue_tracker": "https://github.com/wlcrs/huawei_solar/issues",
"requirements": ["huawei-solar==2.2.8b2"],
"codeowners": ["@wlcrs"],
"iot_class": "local_polling",
"version": "1.2.6b8",
"loggers": ["huawei_solar", "pymodbus"],
}
12 changes: 5 additions & 7 deletions number.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""This component provides number entities for Huawei Solar."""
"""Number entities for Huawei Solar."""
from __future__ import annotations

import logging
Expand All @@ -9,7 +9,7 @@
NumberEntityDescription,
NumberMode,
)
from homeassistant.components.number.const import DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE
from homeassistant.components.number.const import DEFAULT_MAX_VALUE, DEFAULT_MIN_VALUE
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE, POWER_WATT
from homeassistant.core import HomeAssistant, callback
Expand All @@ -21,11 +21,7 @@
from huawei_solar import register_names as rn
from huawei_solar import register_values as rv

from . import (
HuaweiSolarConfigurationUpdateCoordinator,
HuaweiSolarEntity,
HuaweiSolarUpdateCoordinator,
)
from . import HuaweiSolarConfigurationUpdateCoordinator, HuaweiSolarEntity
from .const import (
CONF_ENABLE_PARAMETER_CONFIGURATION,
DATA_CONFIGURATION_UPDATE_COORDINATORS,
Expand Down Expand Up @@ -292,6 +288,7 @@ async def async_set_native_value(self, value: float) -> None:

@property
def native_max_value(self) -> float:
"""Maximum value, possibly determined dynamically using _dynamic_max_value."""
native_max_value = self.entity_description.native_max_value

if self._dynamic_max_value:
Expand All @@ -305,6 +302,7 @@ def native_max_value(self) -> float:

@property
def native_min_value(self) -> float:
"""Minimum value, possibly determined dynamically using _dynamic_min_value."""
native_min_value = self.entity_description.native_min_value

if self._dynamic_min_value:
Expand Down
30 changes: 14 additions & 16 deletions select.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""This component provides switch entities for Huawei Solar."""
"""Switch entities for Huawei Solar."""
from __future__ import annotations

import logging
from collections.abc import Callable
from dataclasses import dataclass
from enum import IntEnum
from typing import Generic, TypeVar, Any
from typing import Any, Generic, TypeVar, TYPE_CHECKING

from homeassistant.components.select import SelectEntity, SelectEntityDescription
from homeassistant.config_entries import ConfigEntry
Expand All @@ -19,18 +19,17 @@
from huawei_solar import register_values as rv
from huawei_solar.registers import REGISTERS

from . import (
HuaweiSolarConfigurationUpdateCoordinator,
HuaweiSolarEntity,
HuaweiSolarUpdateCoordinator,
)
from . import HuaweiSolarConfigurationUpdateCoordinator, HuaweiSolarEntity
from .const import (
CONF_ENABLE_PARAMETER_CONFIGURATION,
DATA_CONFIGURATION_UPDATE_COORDINATORS,
DATA_UPDATE_COORDINATORS,
DOMAIN,
)

if TYPE_CHECKING:
from . import HuaweiSolarUpdateCoordinator

_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -78,13 +77,13 @@ async def async_setup_entry(
_LOGGER.info("Skipping select setup, as parameter configuration is not enabled")
return

update_coordinators = hass.data[DOMAIN][entry.entry_id][
DATA_UPDATE_COORDINATORS
] # type: list[HuaweiSolarUpdateCoordinator]
update_coordinators: list[HuaweiSolarUpdateCoordinator] = hass.data[DOMAIN][
entry.entry_id
][DATA_UPDATE_COORDINATORS]

configuration_update_coordinators = hass.data[DOMAIN][entry.entry_id][
DATA_CONFIGURATION_UPDATE_COORDINATORS
]
configuration_update_coordinators: list[
HuaweiSolarConfigurationUpdateCoordinator
] = hass.data[DOMAIN][entry.entry_id][DATA_CONFIGURATION_UPDATE_COORDINATORS]

# When more than one inverter is present, then we suffix all sensors with '#1', '#2', ...
# The order for these suffixes is the order in which the user entered the slave-ids.
Expand All @@ -94,7 +93,7 @@ async def async_setup_entry(
for idx, (update_coordinator, configuration_update_coordinator) in enumerate(
zip(update_coordinators, configuration_update_coordinators)
):
slave_entities: list[HuaweiSolarSelectEntity] = []
slave_entities: list[HuaweiSolarSelectEntity | StorageModeSelectEntity] = []

bridge = update_coordinator.bridge
device_infos = update_coordinator.device_infos
Expand Down Expand Up @@ -210,8 +209,7 @@ async def async_select_option(self, option) -> None:

@property
def available(self) -> bool:
"""Override available property (from CoordinatorEntity) to take into account
the custom check_is_available_func result"""
"""Override available property (from CoordinatorEntity) to take into account the custom check_is_available_func result."""
available = super().available

if self.entity_description.check_is_available_func and available:
Expand Down
Loading

0 comments on commit f58daf3

Please sign in to comment.