Use pyatmo device type enum instead of string (#103030)

This commit is contained in:
Tobias Sauerwein 2023-11-04 11:28:26 +01:00 committed by GitHub
parent f5fee73e01
commit 96409cf0e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 9 deletions

View file

@ -5,6 +5,7 @@ import logging
from typing import Any, cast
from pyatmo.modules import NATherm1
from pyatmo.modules.device_types import DeviceType
import voluptuous as vol
from homeassistant.components.climate import (
@ -106,8 +107,8 @@ CURRENT_HVAC_MAP_NETATMO = {True: HVACAction.HEATING, False: HVACAction.IDLE}
DEFAULT_MAX_TEMP = 30
NA_THERM = "NATherm1"
NA_VALVE = "NRV"
NA_THERM = DeviceType.NATherm1
NA_VALVE = DeviceType.NRV
async def async_setup_entry(
@ -117,6 +118,10 @@ async def async_setup_entry(
@callback
def _create_entity(netatmo_device: NetatmoRoom) -> None:
if not netatmo_device.room.climate_type:
msg = f"No climate type found for this room: {netatmo_device.room.name}"
_LOGGER.info(msg)
return
entity = NetatmoThermostat(netatmo_device)
async_add_entities([entity])
@ -170,7 +175,8 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
]
)
self._model: str = f"{self._room.climate_type}"
assert self._room.climate_type
self._model: DeviceType = self._room.climate_type
self._config_url = CONF_URL_ENERGY
@ -184,7 +190,7 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
self._selected_schedule = None
self._attr_hvac_modes = [HVACMode.AUTO, HVACMode.HEAT]
if self._model == NA_THERM:
if self._model is NA_THERM:
self._attr_hvac_modes.append(HVACMode.OFF)
self._attr_unique_id = f"{self._room.entity_id}-{self._model}"

View file

@ -12,7 +12,10 @@ from typing import Any
import aiohttp
import pyatmo
from pyatmo.modules.device_types import DeviceCategory as NetatmoDeviceCategory
from pyatmo.modules.device_types import (
DeviceCategory as NetatmoDeviceCategory,
DeviceType as NetatmoDeviceType,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
@ -53,7 +56,7 @@ ACCOUNT = "account"
HOME = "home"
WEATHER = "weather"
AIR_CARE = "air_care"
PUBLIC = "public"
PUBLIC = NetatmoDeviceType.public
EVENT = "event"
PUBLISHERS = {

View file

@ -3,6 +3,7 @@ from __future__ import annotations
from typing import Any
from pyatmo import DeviceType
from pyatmo.modules.device_types import (
DEVICE_DESCRIPTION_MAP,
DeviceType as NetatmoDeviceType,
@ -29,7 +30,7 @@ class NetatmoBase(Entity):
self._device_name: str = ""
self._id: str = ""
self._model: str = ""
self._model: DeviceType
self._config_url: str | None = None
self._attr_name = None
self._attr_unique_id = None

View file

@ -3,6 +3,8 @@ from __future__ import annotations
import logging
from pyatmo import DeviceType
from homeassistant.components.select import SelectEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
@ -65,7 +67,7 @@ class NetatmoScheduleSelect(NetatmoBase, SelectEntity):
self._device_name = self._home.name
self._attr_name = f"{self._device_name}"
self._model: str = "NATherm1"
self._model = DeviceType.NATherm1
self._config_url = CONF_URL_ENERGY
self._attr_unique_id = f"{self._home_id}-schedule-select"

View file

@ -322,6 +322,10 @@ async def async_setup_entry(
@callback
def _create_room_sensor_entity(netatmo_device: NetatmoRoom) -> None:
if not netatmo_device.room.climate_type:
msg = f"No climate type found for this room: {netatmo_device.room.name}"
_LOGGER.info(msg)
return
async_add_entities(
NetatmoRoomSensor(netatmo_device, description)
for description in SENSOR_TYPES
@ -633,9 +637,11 @@ class NetatmoRoomSensor(NetatmoBase, SensorEntity):
self._attr_name = f"{self._room.name} {self.entity_description.name}"
self._room_id = self._room.entity_id
self._model = f"{self._room.climate_type}"
self._config_url = CONF_URL_ENERGY
assert self._room.climate_type
self._model = self._room.climate_type
self._attr_unique_id = (
f"{self._id}-{self._room.entity_id}-{self.entity_description.key}"
)