mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Remove solaredge from mypy ignore list (#74983)
This commit is contained in:
parent
9d2c213903
commit
5f4713a200
@ -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]:
|
||||
|
@ -75,6 +75,7 @@ SENSOR_TYPES = [
|
||||
),
|
||||
SolarEdgeSensorEntityDescription(
|
||||
key="site_details",
|
||||
json_key="status",
|
||||
name="Site details",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from abc import abstractmethod
|
||||
from datetime import date, datetime, timedelta
|
||||
from typing import Any
|
||||
|
||||
from solaredge import Solaredge
|
||||
from stringcase import snakecase
|
||||
@ -23,16 +24,17 @@ from .const import (
|
||||
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:
|
||||
@ -105,12 +107,6 @@ class SolarEdgeOverviewDataService(SolarEdgeDataService):
|
||||
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."""
|
||||
@ -125,7 +121,7 @@ class SolarEdgeDetailsDataService(SolarEdgeDataService):
|
||||
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():
|
||||
@ -143,9 +139,13 @@ class SolarEdgeDetailsDataService(SolarEdgeDataService):
|
||||
]:
|
||||
self.attributes[key] = value
|
||||
elif key == "status":
|
||||
self.data = value
|
||||
self.data["status"] = value
|
||||
|
||||
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):
|
||||
|
@ -7,7 +7,14 @@ from homeassistant.components.sensor import SensorEntityDescription
|
||||
|
||||
|
||||
@dataclass
|
||||
class SolarEdgeSensorEntityDescription(SensorEntityDescription):
|
||||
"""Sensor entity description for SolarEdge."""
|
||||
class SolarEdgeSensorEntityRequiredKeyMixin:
|
||||
"""Sensor entity description with json_key for SolarEdge."""
|
||||
|
||||
json_key: str | None = None
|
||||
json_key: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class SolarEdgeSensorEntityDescription(
|
||||
SensorEntityDescription, SolarEdgeSensorEntityRequiredKeyMixin
|
||||
):
|
||||
"""Sensor entity description for SolarEdge."""
|
||||
|
@ -101,7 +101,7 @@ class SolarEdgeSensorFactory:
|
||||
|
||||
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]
|
||||
|
||||
@ -155,7 +155,7 @@ class SolarEdgeDetailsSensor(SolarEdgeSensorEntity):
|
||||
@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:
|
||||
@ -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)
|
||||
|
||||
@ -182,14 +182,19 @@ class SolarEdgeInventorySensor(SolarEdgeSensorEntity):
|
||||
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)
|
||||
|
||||
@ -208,7 +213,7 @@ class SolarEdgePowerFlowSensor(SolarEdgeSensorEntity):
|
||||
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)
|
||||
@ -216,7 +221,7 @@ class SolarEdgePowerFlowSensor(SolarEdgeSensorEntity):
|
||||
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)
|
||||
|
||||
|
9
mypy.ini
9
mypy.ini
@ -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
|
||||
|
||||
|
@ -51,9 +51,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
||||
"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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user