8000 Improve smarla base entity by rlint-explicatis · Pull Request #145710 · home-assistant/core · GitHub
[go: up one dir, main page]

Skip to content

Improve smarla base entity #145710

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions homeassistant/components/smarla/entity.py
8000
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
"""Common base for entities."""

from dataclasses import dataclass
from typing import Any

from pysmarlaapi import Federwiege
from pysmarlaapi.federwiege.classes import Property

from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity import Entity, EntityDescription

from .const import DEVICE_MODEL_NAME, DOMAIN, MANUFACTURER_NAME


@dataclass(frozen=True, kw_only=True)
class SmarlaEntityDescription(EntityDescription):
"""Class describing Swing2Sleep Smarla entities."""

service: str
property: str


class SmarlaBaseEntity(Entity):
"""Common Base Entity class for defining Smarla device."""

entity_description: SmarlaEntityDescription

_attr_should_poll = False
_attr_has_entity_name = True

def __init__(self, federwiege: Federwiege, prop: Property) -> None:
def __init__(self, federwiege: Federwiege, desc: SmarlaEntityDescription) -> None:
"""Initialise the entity."""
self._property = prop
self.entity_description = desc
self._property = federwiege.get_property(desc.service, desc.property)
self._attr_unique_id = f"{federwiege.serial_number}-{desc.key}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, federwiege.serial_number)},
name=DEVICE_MODEL_NAME,
Expand Down
19 changes: 2 additions & 17 deletions homeassistant/components/smarla/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@
from dataclasses import dataclass
from typing import Any

from pysmarlaapi import Federwiege
from pysmarlaapi.federwiege.classes import Property

from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback

from . import FederwiegeConfigEntry
from .entity import SmarlaBaseEntity
from .entity import SmarlaBaseEntity, SmarlaEntityDescription


@dataclass(frozen=True, kw_only=True)
class SmarlaSwitchEntityDescription(SwitchEntityDescription):
class SmarlaSwitchEntityDescription(SmarlaEntityDescription, SwitchEntityDescription):
"""Class describing Swing2Sleep Smarla switch entity."""

service: str
property: str


SWITCHES: list[SmarlaSwitchEntityDescription] = [
SmarlaSwitchEntityDescription(
Expand Down Expand Up @@ -55,17 +51,6 @@ class SmarlaSwitch(SmarlaBaseEntity, SwitchEntity):

_property: Property[bool]

def __init__(
self,
federwiege: Federwiege,
desc: SmarlaSwitchEntityDescription,
) -> None:
"""Initialize a Smarla switch."""
prop = federwiege.get_property(desc.service, desc.property)
super().__init__(federwiege, prop)
self.entity_description = desc
self._attr_unique_id = f"{federwiege.serial_number}-{desc.key}"

@property
def is_on(self) -> bool:
"""Return the entity value to represent the entity state."""
Expand Down
0