core/homeassistant/components/renson/__init__.py

89 lines
2.4 KiB
Python
Raw Normal View History

Renson integration (#56374) * Implemented Renson integration * - renamed component to a better name - Made cleaner code by splitting up files into different one - Fixed issues regarding getting data from library - Added service.yaml file * Added Renson services * cleanup translations * added config_flow tests * changed config_flow, removed all services * use SensorEntityDescription + introduced new binarySensor * fixed config_flow test * renamed renson_endura_delta to renson * refactored sensors and implemented binary_sensor * Changed some sensors to non measurement and added entity_registery_enabled_default for config sensors * Enabled binary_sensor * changed import to new renamed module * Merge files into correct files + cleaned some code * Change use of EntityDescription * Update codeowners * Fixed lint issues * Fix sensor * Create test.yml * Update test.yml * add github action tests * Format json files * Remove deprecated code * Update homeassistant/components/renson/binary_sensor.py Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Use Coordinqte in Sensor * Migrated binary sensor to use coordinate * Removed firmwareSensor * Add entity_catogory to binary_sensor * Add services * Revert "Add services" This reverts commit 028760d8d8454ce98cf14eed0c7927d228ccd5e6. * update requirements of Renson integration * Add services and fan * Fixed some issue + fixed PR comments * Cleanup code * Go back 2 years ago to the bare minimum for PR approval * Refactored code and added a lot of device classes to the entities * Fix some bugs * Add unique Id and some device class * Show the level value for CURRENT_LEVEL_FIELD instead of the raw data * Remove FILTER_PRESET_FIELD for now * Make the _attr_unique_id unique * Changed Renson tests * Moved Renson hass data into @dataclass * Changed test + added files to .coveragerc * Add device_class=SensorDeviceClass.Duration * Fix syntax --------- Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2023-06-10 07:21:33 +00:00
"""The Renson integration."""
from __future__ import annotations
from dataclasses import dataclass
from datetime import timedelta
import logging
2023-06-11 00:28:32 +00:00
from typing import Any
Renson integration (#56374) * Implemented Renson integration * - renamed component to a better name - Made cleaner code by splitting up files into different one - Fixed issues regarding getting data from library - Added service.yaml file * Added Renson services * cleanup translations * added config_flow tests * changed config_flow, removed all services * use SensorEntityDescription + introduced new binarySensor * fixed config_flow test * renamed renson_endura_delta to renson * refactored sensors and implemented binary_sensor * Changed some sensors to non measurement and added entity_registery_enabled_default for config sensors * Enabled binary_sensor * changed import to new renamed module * Merge files into correct files + cleaned some code * Change use of EntityDescription * Update codeowners * Fixed lint issues * Fix sensor * Create test.yml * Update test.yml * add github action tests * Format json files * Remove deprecated code * Update homeassistant/components/renson/binary_sensor.py Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Use Coordinqte in Sensor * Migrated binary sensor to use coordinate * Removed firmwareSensor * Add entity_catogory to binary_sensor * Add services * Revert "Add services" This reverts commit 028760d8d8454ce98cf14eed0c7927d228ccd5e6. * update requirements of Renson integration * Add services and fan * Fixed some issue + fixed PR comments * Cleanup code * Go back 2 years ago to the bare minimum for PR approval * Refactored code and added a lot of device classes to the entities * Fix some bugs * Add unique Id and some device class * Show the level value for CURRENT_LEVEL_FIELD instead of the raw data * Remove FILTER_PRESET_FIELD for now * Make the _attr_unique_id unique * Changed Renson tests * Moved Renson hass data into @dataclass * Changed test + added files to .coveragerc * Add device_class=SensorDeviceClass.Duration * Fix syntax --------- Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2023-06-10 07:21:33 +00:00
import async_timeout
from renson_endura_delta.renson import RensonVentilation
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
PLATFORMS = [
Platform.SENSOR,
]
@dataclass
class RensonData:
"""Renson data class."""
api: RensonVentilation
coordinator: RensonCoordinator
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Renson from a config entry."""
api = RensonVentilation(entry.data[CONF_HOST])
coordinator = RensonCoordinator("Renson", hass, api)
if not await hass.async_add_executor_job(api.connect):
raise ConfigEntryNotReady("Cannot connect to Renson device")
await coordinator.async_config_entry_first_refresh()
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = RensonData(
api,
coordinator,
)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok
class RensonCoordinator(DataUpdateCoordinator):
"""Data update coordinator for Renson."""
def __init__(
self,
name: str,
hass: HomeAssistant,
api: RensonVentilation,
update_interval=timedelta(seconds=30),
) -> None:
"""Initialize my coordinator."""
super().__init__(
hass,
_LOGGER,
# Name of the data. For logging purposes.
name=name,
# Polling interval. Will only be polled if there are subscribers.
update_interval=update_interval,
)
self.api = api
2023-06-11 00:28:32 +00:00
async def _async_update_data(self) -> dict[str, Any]:
Renson integration (#56374) * Implemented Renson integration * - renamed component to a better name - Made cleaner code by splitting up files into different one - Fixed issues regarding getting data from library - Added service.yaml file * Added Renson services * cleanup translations * added config_flow tests * changed config_flow, removed all services * use SensorEntityDescription + introduced new binarySensor * fixed config_flow test * renamed renson_endura_delta to renson * refactored sensors and implemented binary_sensor * Changed some sensors to non measurement and added entity_registery_enabled_default for config sensors * Enabled binary_sensor * changed import to new renamed module * Merge files into correct files + cleaned some code * Change use of EntityDescription * Update codeowners * Fixed lint issues * Fix sensor * Create test.yml * Update test.yml * add github action tests * Format json files * Remove deprecated code * Update homeassistant/components/renson/binary_sensor.py Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Use Coordinqte in Sensor * Migrated binary sensor to use coordinate * Removed firmwareSensor * Add entity_catogory to binary_sensor * Add services * Revert "Add services" This reverts commit 028760d8d8454ce98cf14eed0c7927d228ccd5e6. * update requirements of Renson integration * Add services and fan * Fixed some issue + fixed PR comments * Cleanup code * Go back 2 years ago to the bare minimum for PR approval * Refactored code and added a lot of device classes to the entities * Fix some bugs * Add unique Id and some device class * Show the level value for CURRENT_LEVEL_FIELD instead of the raw data * Remove FILTER_PRESET_FIELD for now * Make the _attr_unique_id unique * Changed Renson tests * Moved Renson hass data into @dataclass * Changed test + added files to .coveragerc * Add device_class=SensorDeviceClass.Duration * Fix syntax --------- Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2023-06-10 07:21:33 +00:00
"""Fetch data from API endpoint."""
async with async_timeout.timeout(30):
return await self.hass.async_add_executor_job(self.api.get_all_data)