1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-20 02:48:57 +00:00
Files
core/homeassistant/components/chacon_dio/entity.py
cnico 092e362f01 Add new integration for Dio Chacon cover devices (#116267)
* Dio Chacon integration addition with config flow and cover entity

* Addition of model information for device

* Addition of light and service to force reloading states

* Logger improvements

* Convert light to switch and usage of v1.0.0 of the api

* 100% for tests coverage

* Invalid credential implementation and rebase on latest ha dev code

* Simplify PR with only one platform

* Ruff correction

* restore original .gitignore content

* Correction of cover state bug when using cover when using actions on cover group.

* Begin of corrections following review.

* unit tests correction

* Refactor with a coordinator as asked by review

* Implemented a post constructor callback init method via dio-chacon-api-1.0.2. Improved typing.

* Corrections for 2nd review

* Reimplemented without coordinator as reviewed with Joostlek

* Review improvement

* generalize callback in entity

* Other review improvements

* Refactored tests for readability

* Test 100% operationals

* Tests review corrections

* Tests review corrections

* Review tests improvements

* simplified tests with snapshots and callback method

* Final fixes

* Final fixes

* Final fixes

* Rename to chacon_dio

---------

Co-authored-by: Joostlek <joostlek@outlook.com>
2024-07-04 16:45:20 +02:00

54 lines
1.6 KiB
Python

"""Base entity for the Chacon Dio entity."""
import logging
from typing import Any
from dio_chacon_wifi_api import DIOChaconAPIClient
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity import Entity
from .const import DOMAIN, MANUFACTURER
_LOGGER = logging.getLogger(__name__)
class ChaconDioEntity(Entity):
"""Implements a common class elements representing the Chacon Dio entity."""
_attr_should_poll = False
_attr_has_entity_name = True
def __init__(self, client: DIOChaconAPIClient, device: dict[str, Any]) -> None:
"""Initialize Chacon Dio entity."""
self.client = client
self.target_id: str = device["id"]
self._attr_unique_id = self.target_id
self._attr_device_info: DeviceInfo | None = DeviceInfo(
identifiers={(DOMAIN, self.target_id)},
manufacturer=MANUFACTURER,
name=device["name"],
model=device["model"],
)
self._update_attr(device)
def _update_attr(self, data: dict[str, Any]) -> None:
"""Recomputes the attributes values."""
async def async_added_to_hass(self) -> None:
"""Register the callback for server side events."""
await super().async_added_to_hass()
self.client.set_callback_device_state_by_device(
self.target_id, self.callback_device_state
)
def callback_device_state(self, data: dict[str, Any]) -> None:
"""Receive callback for device state notification pushed from the server."""
_LOGGER.debug("Data received from server %s", data)
self._update_attr(data)
self.async_write_ha_state()