Skip to content

Commit

Permalink
Use pyatmo device type enum instead of string (#103030)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgtobi authored Nov 4, 2023
1 parent f5fee73 commit 96409cf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
14 changes: 10 additions & 4 deletions homeassistant/components/netatmo/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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 (
Expand Down Expand Up @@ -106,8 +107,8 @@

DEFAULT_MAX_TEMP = 30

NA_THERM = "NATherm1"
NA_VALVE = "NRV"
NA_THERM = DeviceType.NATherm1
NA_VALVE = DeviceType.NRV


async def async_setup_entry(
Expand All @@ -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])

Expand Down Expand Up @@ -170,7 +175,8 @@ def __init__(self, netatmo_device: NetatmoRoom) -> None:
]
)

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

Expand All @@ -184,7 +190,7 @@ def __init__(self, netatmo_device: NetatmoRoom) -> None:
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}"
Expand Down
7 changes: 5 additions & 2 deletions homeassistant/components/netatmo/data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

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
Expand Down Expand Up @@ -53,7 +56,7 @@
HOME = "home"
WEATHER = "weather"
AIR_CARE = "air_care"
PUBLIC = "public"
PUBLIC = NetatmoDeviceType.public
EVENT = "event"

PUBLISHERS = {
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/netatmo/netatmo_entity_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from typing import Any

from pyatmo import DeviceType
from pyatmo.modules.device_types import (
DEVICE_DESCRIPTION_MAP,
DeviceType as NetatmoDeviceType,
Expand All @@ -29,7 +30,7 @@ def __init__(self, data_handler: NetatmoDataHandler) -> None:

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
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/netatmo/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import logging

from pyatmo import DeviceType

from homeassistant.components.select import SelectEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
Expand Down Expand Up @@ -65,7 +67,7 @@ def __init__(
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"
Expand Down
8 changes: 7 additions & 1 deletion homeassistant/components/netatmo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ def _create_sensor_entity(netatmo_device: NetatmoDevice) -> None:

@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
Expand Down Expand Up @@ -633,9 +637,11 @@ def __init__(

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}"
)
Expand Down

0 comments on commit 96409cf

Please sign in to comment.