Skip to content

Commit

Permalink
Fix more statics, which should be class variables (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
torbennehmer authored Apr 10, 2024
2 parents 8723d02 + 42d0908 commit f7c88f1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 38 deletions.
8 changes: 3 additions & 5 deletions custom_components/e3dc_rscp/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ async def async_setup_entry(
class E3DCBinarySensor(CoordinatorEntity, BinarySensorEntity):
"""Custom E3DC Binary Sensor implementation."""

coordinator: E3DCCoordinator
entity_description: E3DCBinarySensorEntityDescription
_attr_has_entity_name: bool = True
_custom_icons: bool = False

def __init__(
self,
Expand All @@ -87,9 +84,10 @@ def __init__(
) -> None:
"""Initialize the Sensor."""
super().__init__(coordinator)
self.entity_description = description
self.coordinator: E3DCCoordinator = coordinator
self.entity_description: E3DCBinarySensorEntityDescription = description
self._attr_unique_id = f"{uid}_{description.key}"
self._custom_icons = (
self._custom_icons: bool = (
self.entity_description.on_icon is not None
and self.entity_description.off_icon is not None
)
Expand Down
18 changes: 6 additions & 12 deletions custom_components/e3dc_rscp/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,14 @@ async def async_get_config_entry_diagnostics(
class _DiagnosticsDumper:
"""Helper class to collect a diagnostic dump in a failsafe way."""

e3dc: E3DC = None
coordinator: E3DCCoordinator = None
proxy: E3DCProxy = None
hass: HomeAssistant = None
entry: ConfigEntry = None
result: dict[str, Any] = {}

def __init__(self, _hass: HomeAssistant, _entry: ConfigEntry):
"""Initialize the dumper and set up a few references."""
self.hass = _hass
self.entry = _entry
self.coordinator = self.hass.data[DOMAIN][self.entry.unique_id]
self.proxy = self.coordinator.proxy
self.e3dc = self.proxy.e3dc
self.hass: HomeAssistant = _hass
self.entry: ConfigEntry = _entry
self.coordinator: E3DCCoordinator = self.hass.data[DOMAIN][self.entry.unique_id]
self.proxy: E3DCProxy = self.coordinator.proxy
self.e3dc: E3DC = self.proxy.e3dc
self.result: dict[str, Any] = {}

def create_dump(self):
"""Create the dump data and redact pricate data, central call-in point."""
Expand Down
22 changes: 9 additions & 13 deletions custom_components/e3dc_rscp/e3dc_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,17 @@ def wrapper_handle_e3dc_ex(*args, **kwargs) -> Any:
class E3DCProxy:
"""Proxies requests to pye3dc, takes care of error and async handling."""

# TODO: move to readonly properties
e3dc: E3DC = None
e3dc_config: dict[str, Any] = None
_hass: HomeAssistant = None
_config: ConfigEntry = None
_host: str
_username: str
_password: str
_rscpkey: str

def __init__(self, _hass: HomeAssistant, _config: ConfigEntry | dict[str, str]):
"""Initialize E3DC Proxy and connect."""
self._hass = _hass
self._config = _config
self.e3dc_config = {}
# TODO: move to readonly properties
self.e3dc: E3DC = None
self.e3dc_config: dict[str, Any] = {}
self._hass: HomeAssistant = _hass
self._config: ConfigEntry = _config
self._host: str
self._username: str
self._password: str
self._rscpkey: str

if isinstance(_config, ConfigEntry):
self._host = self._config.data.get(CONF_HOST)
Expand Down
5 changes: 2 additions & 3 deletions custom_components/e3dc_rscp/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,6 @@ async def async_setup_entry(
class E3DCSensor(CoordinatorEntity, SensorEntity):
"""Custom E3DC Sensor implementation."""

coordinator: E3DCCoordinator
entity_description: SensorEntityDescription
_attr_has_entity_name = True

def __init__(
Expand All @@ -437,7 +435,8 @@ def __init__(
) -> None:
"""Initialize the Sensor."""
super().__init__(coordinator)
self.entity_description = description
self.coordinator: E3DCCoordinator = coordinator
self.entity_description: SensorEntityDescription = description
self._attr_unique_id = f"{uid}_{description.key}"

@property
Expand Down
8 changes: 3 additions & 5 deletions custom_components/e3dc_rscp/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ async def async_setup_entry(
class E3DCSwitch(CoordinatorEntity, SwitchEntity):
"""Custom E3DC Switch Implementation."""

coordinator: E3DCCoordinator
entity_description: E3DCSwitchEntityDescription
_attr_has_entity_name = True
_has_custom_icons: bool = False

def __init__(
self,
Expand All @@ -98,10 +95,11 @@ def __init__(
) -> None:
"""Initialize the Sensor."""
super().__init__(coordinator)
self.entity_description = description
self.coordinator: E3DCCoordinator = coordinator
self.entity_description: E3DCSwitchEntityDescription = description
self._attr_is_on = self.coordinator.data.get(self.entity_description.key)
self._attr_unique_id = f"{uid}_{description.key}"
self._has_custom_icons = (
self._has_custom_icons: bool = (
self.entity_description.on_icon is not None
and self.entity_description.off_icon is not None
)
Expand Down

0 comments on commit f7c88f1

Please sign in to comment.