Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove solaredge from mypy ignore list #74983

Merged
merged 1 commit into from Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/solaredge/config_flow.py
Expand Up @@ -23,7 +23,7 @@ class SolarEdgeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):

def __init__(self) -> None:
"""Initialize the config flow."""
self._errors = {}
self._errors: dict[str, str] = {}

@callback
def _async_current_site_ids(self) -> set[str]:
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/solaredge/const.py
Expand Up @@ -75,6 +75,7 @@
),
SolarEdgeSensorEntityDescription(
key="site_details",
json_key="status",
name="Site details",
entity_registry_enabled_default=False,
),
Expand Down
24 changes: 12 additions & 12 deletions homeassistant/components/solaredge/coordinator.py
Expand Up @@ -3,6 +3,7 @@

from abc import abstractmethod
from datetime import date, datetime, timedelta
from typing import Any

from solaredge import Solaredge
from stringcase import snakecase
Expand All @@ -23,16 +24,17 @@
class SolarEdgeDataService:
"""Get and update the latest data."""

coordinator: DataUpdateCoordinator

def __init__(self, hass: HomeAssistant, api: Solaredge, site_id: str) -> None:
"""Initialize the data object."""
self.api = api
self.site_id = site_id

self.data = {}
self.attributes = {}
self.data: dict[str, Any] = {}
self.attributes: dict[str, Any] = {}

self.hass = hass
self.coordinator = None

@callback
def async_setup(self) -> None:
Expand Down Expand Up @@ -105,12 +107,6 @@ def update(self) -> None:
class SolarEdgeDetailsDataService(SolarEdgeDataService):
"""Get and update the latest details data."""

def __init__(self, hass: HomeAssistant, api: Solaredge, site_id: str) -> None:
"""Initialize the details data service."""
super().__init__(hass, api, site_id)

self.data = None

@property
def update_interval(self) -> timedelta:
"""Update interval."""
Expand All @@ -125,7 +121,7 @@ def update(self) -> None:
except KeyError as ex:
raise UpdateFailed("Missing details data, skipping update") from ex

self.data = None
self.data = {}
self.attributes = {}

for key, value in details.items():
Expand All @@ -143,9 +139,13 @@ def update(self) -> None:
]:
self.attributes[key] = value
elif key == "status":
self.data = value
self.data["status"] = value
Copy link
Contributor Author

@epenet epenet Jul 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have adjust SolarEdgeDetailsDataService to return a dict like all other coordinators.
This avoids adding conditions all around for handling str | dict | None


LOGGER.debug("Updated SolarEdge details: %s, %s", self.data, self.attributes)
LOGGER.debug(
"Updated SolarEdge details: %s, %s",
self.data.get("status"),
self.attributes,
)


class SolarEdgeInventoryDataService(SolarEdgeDataService):
Expand Down
13 changes: 10 additions & 3 deletions homeassistant/components/solaredge/models.py
Expand Up @@ -7,7 +7,14 @@


@dataclass
class SolarEdgeSensorEntityDescription(SensorEntityDescription):
"""Sensor entity description for SolarEdge."""
class SolarEdgeSensorEntityRequiredKeyMixin:
"""Sensor entity description with json_key for SolarEdge."""

json_key: str


json_key: str | None = None
@dataclass
class SolarEdgeSensorEntityDescription(
SensorEntityDescription, SolarEdgeSensorEntityRequiredKeyMixin
):
"""Sensor entity description for SolarEdge."""
19 changes: 12 additions & 7 deletions homeassistant/components/solaredge/sensor.py
Expand Up @@ -101,7 +101,7 @@ def __init__(

def create_sensor(
self, sensor_type: SolarEdgeSensorEntityDescription
) -> SolarEdgeSensorEntityDescription:
) -> SolarEdgeSensorEntity:
"""Create and return a sensor based on the sensor_key."""
sensor_class, service = self.services[sensor_type.key]

Expand Down Expand Up @@ -155,7 +155,7 @@ def extra_state_attributes(self) -> dict[str, Any]:
@property
def native_value(self) -> str | None:
"""Return the state of the sensor."""
return self.data_service.data
return self.data_service.data.get(self.entity_description.json_key)

@property
def unique_id(self) -> str | None:
Expand All @@ -169,7 +169,7 @@ class SolarEdgeInventorySensor(SolarEdgeSensorEntity):
"""Representation of an SolarEdge Monitoring API inventory sensor."""

@property
def extra_state_attributes(self) -> dict[str, Any]:
def extra_state_attributes(self) -> dict[str, Any] | None:
"""Return the state attributes."""
return self.data_service.attributes.get(self.entity_description.json_key)

Expand All @@ -182,14 +182,19 @@ def native_value(self) -> str | None:
class SolarEdgeEnergyDetailsSensor(SolarEdgeSensorEntity):
"""Representation of an SolarEdge Monitoring API power flow sensor."""

def __init__(self, platform_name, sensor_type, data_service):
def __init__(
self,
platform_name: str,
sensor_type: SolarEdgeSensorEntityDescription,
data_service: SolarEdgeEnergyDetailsService,
) -> None:
"""Initialize the power flow sensor."""
super().__init__(platform_name, sensor_type, data_service)

self._attr_native_unit_of_measurement = data_service.unit

@property
def extra_state_attributes(self) -> dict[str, Any]:
def extra_state_attributes(self) -> dict[str, Any] | None:
"""Return the state attributes."""
return self.data_service.attributes.get(self.entity_description.json_key)

Expand All @@ -208,15 +213,15 @@ def __init__(
self,
platform_name: str,
description: SolarEdgeSensorEntityDescription,
data_service: SolarEdgeDataService,
data_service: SolarEdgePowerFlowDataService,
) -> None:
"""Initialize the power flow sensor."""
super().__init__(platform_name, description, data_service)

self._attr_native_unit_of_measurement = data_service.unit

@property
def extra_state_attributes(self) -> dict[str, Any]:
def extra_state_attributes(self) -> dict[str, Any] | None:
"""Return the state attributes."""
return self.data_service.attributes.get(self.entity_description.json_key)

Expand Down
9 changes: 0 additions & 9 deletions mypy.ini
Expand Up @@ -2750,15 +2750,6 @@ ignore_errors = true
[mypy-homeassistant.components.profiler]
ignore_errors = true

[mypy-homeassistant.components.solaredge.config_flow]
ignore_errors = true

[mypy-homeassistant.components.solaredge.coordinator]
ignore_errors = true

[mypy-homeassistant.components.solaredge.sensor]
ignore_errors = true

[mypy-homeassistant.components.sonos]
ignore_errors = true

Expand Down
3 changes: 0 additions & 3 deletions script/hassfest/mypy_config.py
Expand Up @@ -51,9 +51,6 @@
"homeassistant.components.onvif.sensor",
"homeassistant.components.plex.media_player",
"homeassistant.components.profiler",
"homeassistant.components.solaredge.config_flow",
"homeassistant.components.solaredge.coordinator",
"homeassistant.components.solaredge.sensor",
"homeassistant.components.sonos",
"homeassistant.components.sonos.alarms",
"homeassistant.components.sonos.binary_sensor",
Expand Down