Skip to content

Commit

Permalink
Small cleanups to enphase_envoy select platform (#98476)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Aug 15, 2023
1 parent 9253527 commit 73f882b
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions homeassistant/components/enphase_envoy/select.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Select platform for Enphase Envoy solar energy monitor."""
from __future__ import annotations

from collections.abc import Callable
from collections.abc import Callable, Coroutine
from dataclasses import dataclass
from typing import Any

from pyenphase import EnvoyDryContactSettings
from pyenphase import Envoy, EnvoyDryContactSettings
from pyenphase.models.dry_contacts import DryContactAction, DryContactMode

from homeassistant.components.select import SelectEntity, SelectEntityDescription
Expand All @@ -24,7 +24,9 @@ class EnvoyRelayRequiredKeysMixin:
"""Mixin for required keys."""

value_fn: Callable[[EnvoyDryContactSettings], str]
update_fn: Callable[[Any, Any, Any], Any]
update_fn: Callable[
[Envoy, EnvoyDryContactSettings, str], Coroutine[Any, Any, dict[str, Any]]
]


@dataclass
Expand Down Expand Up @@ -129,36 +131,34 @@ def __init__(
self,
coordinator: EnphaseUpdateCoordinator,
description: EnvoyRelaySelectEntityDescription,
relay: str,
relay_id: str,
) -> None:
"""Initialize the Enphase relay select entity."""
super().__init__(coordinator, description)
self.envoy = coordinator.envoy
assert self.envoy is not None
assert self.data is not None
self.enpower = self.data.enpower
assert self.enpower is not None
self._serial_number = self.enpower.serial_number
self.relay = self.data.dry_contact_settings[relay]
self.relay_id = relay
self._attr_unique_id = (
f"{self._serial_number}_relay_{relay}_{self.entity_description.key}"
)
enpower = self.data.enpower
assert enpower is not None
serial_number = enpower.serial_number
self._relay_id = relay_id
self._attr_unique_id = f"{serial_number}_relay_{relay_id}_{description.key}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, relay)},
identifiers={(DOMAIN, relay_id)},
manufacturer="Enphase",
model="Dry contact relay",
name=self.relay.load_name,
sw_version=str(self.enpower.firmware_version),
via_device=(DOMAIN, self._serial_number),
sw_version=str(enpower.firmware_version),
via_device=(DOMAIN, serial_number),
)

@property
def relay(self) -> EnvoyDryContactSettings:
"""Return the relay object."""
return self.data.dry_contact_settings[self._relay_id]

@property
def current_option(self) -> str:
"""Return the state of the Enpower switch."""
return self.entity_description.value_fn(
self.data.dry_contact_settings[self.relay_id]
)
return self.entity_description.value_fn(self.relay)

async def async_select_option(self, option: str) -> None:
"""Update the relay."""
Expand Down

0 comments on commit 73f882b

Please sign in to comment.