Skip to content

Commit

Permalink
thermostat: move to its own file
Browse files Browse the repository at this point in the history
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
  • Loading branch information
Noltari committed May 26, 2023
1 parent daf8ae3 commit b1e048a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 44 deletions.
45 changes: 1 addition & 44 deletions aioairzone/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
SleepTimeout,
SystemType,
TemperatureUnit,
ThermostatType,
)
from .const import (
API_AIR_DEMAND,
Expand Down Expand Up @@ -58,9 +57,6 @@
API_SYSTEM_ID,
API_SYSTEM_TYPE,
API_TEMP_STEP,
API_THERMOS_FIRMWARE,
API_THERMOS_RADIO,
API_THERMOS_TYPE,
API_UNITS,
API_ZONE_ID,
AZD_ABS_TEMP_MAX,
Expand Down Expand Up @@ -121,10 +117,9 @@
DEFAULT_TEMP_STEP_FAHRENHEIT,
ERROR_SYSTEM,
ERROR_ZONE,
THERMOSTAT_RADIO,
THERMOSTAT_WIRED,
)
from .exceptions import InvalidZone
from .thermostat import Thermostat

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -327,44 +322,6 @@ def update_data(self, data: dict[str, Any]) -> None:
self.type = SystemType(data[API_SYSTEM_TYPE])


class Thermostat:
"""Airzone Thermostat."""

def __init__(self, data: dict[str, Any]):
"""Thermostat init."""
self.firmware: str | None = None
self.radio: bool | None = None
self.type: ThermostatType | None = None

if API_THERMOS_FIRMWARE in data:
self.firmware = str(data[API_THERMOS_FIRMWARE])
if API_THERMOS_RADIO in data:
self.radio = bool(data[API_THERMOS_RADIO])
if API_THERMOS_TYPE in data:
self.type = ThermostatType(data[API_THERMOS_TYPE])

def get_firmware(self) -> str | None:
"""Return Airzone Thermostat firmware."""
if self.firmware and "." not in self.firmware and len(self.firmware) > 2:
return f"{self.firmware[0:1]}.{self.firmware[1:]}"
return self.firmware

def get_model(self) -> str | None:
"""Return Airzone Thermostat model."""
if self.type:
name = str(self.type)
if self.type.exists_radio():
sfx = f" ({THERMOSTAT_RADIO if self.radio else THERMOSTAT_WIRED})"
else:
sfx = ""
return f"{name}{sfx}"
return None

def get_radio(self) -> bool | None:
"""Return Airzone Thermostat radio."""
return self.radio


class Zone:
"""Airzone Zone."""

Expand Down
51 changes: 51 additions & 0 deletions aioairzone/thermostat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Airzone Local API Thermostat."""
from __future__ import annotations

from typing import Any

from .common import ThermostatType
from .const import (
API_THERMOS_FIRMWARE,
API_THERMOS_RADIO,
API_THERMOS_TYPE,
THERMOSTAT_RADIO,
THERMOSTAT_WIRED,
)


class Thermostat:
"""Airzone Thermostat."""

def __init__(self, data: dict[str, Any]):
"""Thermostat init."""
self.firmware: str | None = None
self.radio: bool | None = None
self.type: ThermostatType | None = None

if API_THERMOS_FIRMWARE in data:
self.firmware = str(data[API_THERMOS_FIRMWARE])
if API_THERMOS_RADIO in data:
self.radio = bool(data[API_THERMOS_RADIO])
if API_THERMOS_TYPE in data:
self.type = ThermostatType(data[API_THERMOS_TYPE])

def get_firmware(self) -> str | None:
"""Return Airzone Thermostat firmware."""
if self.firmware and "." not in self.firmware and len(self.firmware) > 2:
return f"{self.firmware[0:1]}.{self.firmware[1:]}"
return self.firmware

def get_model(self) -> str | None:
"""Return Airzone Thermostat model."""
if self.type:
name = str(self.type)
if self.type.exists_radio():
sfx = f" ({THERMOSTAT_RADIO if self.radio else THERMOSTAT_WIRED})"
else:
sfx = ""
return f"{name}{sfx}"
return None

def get_radio(self) -> bool | None:
"""Return Airzone Thermostat radio."""
return self.radio

0 comments on commit b1e048a

Please sign in to comment.