diff --git a/pyalarmdotcomajax/__init__.py b/pyalarmdotcomajax/__init__.py index d10fc65..8e091e2 100644 --- a/pyalarmdotcomajax/__init__.py +++ b/pyalarmdotcomajax/__init__.py @@ -21,6 +21,7 @@ BaseDevice, DeviceTypeSpecificData, TroubleCondition, + UserProfile, ) from pyalarmdotcomajax.devices.partition import Partition from pyalarmdotcomajax.devices.registry import ( @@ -47,7 +48,7 @@ ) from pyalarmdotcomajax.websockets.client import WebSocketClient, WebSocketState -__version__ = "0.5.7" +__version__ = "0.5.8" log = logging.getLogger(__name__) @@ -125,6 +126,10 @@ def __init__( self._user_email: str | None = None self._active_system_id: str | None = None + self._user_profile: UserProfile = { + "uses_celsius": False, + } + self._ajax_headers = { "Accept": "application/vnd.api+json", "User-Agent": f"pyalarmdotcomajax/{__version__}", @@ -136,10 +141,6 @@ def __init__( {} ) # Individual devices don't list their associated partitions. This map is used to retrieve partition id when each device is created. - self._installed_device_types: set[DeviceType] = ( - set() - ) # List of device types that are present in a user's environment. We'll use this to cut down on the number of API calls made. - self._trouble_conditions: dict = {} self.devices: DeviceRegistry = DeviceRegistry() @@ -595,6 +596,12 @@ async def async_login( except KeyError: self._keep_alive_url = self.KEEP_ALIVE_DEFAULT_URL + # Determines whether user uses celsius or fahrenheit. This is used for conversions within thermostats. + with contextlib.suppress(KeyError): + self._user_profile["uses_celsius"] = json_rsp["data"][0]["attributes"][ + "localizeTempUnitsToCelsius" + ] + log.debug("*** START IDENTITY INFO ***") log.debug(f"Provider: {self._provider_name}") log.debug(f"User: {self._user_id} {self._user_email}") @@ -822,6 +829,7 @@ async def _async_update__build_device( return device_class( id_=entity_id, raw_device_data=raw_device, + user_profile=self._user_profile, children=children, device_type_specific_data=device_type_specific_data.get(entity_id), send_action_callback=self.async_send_command, diff --git a/pyalarmdotcomajax/devices/__init__.py b/pyalarmdotcomajax/devices/__init__.py index 1868819..914f31a 100644 --- a/pyalarmdotcomajax/devices/__init__.py +++ b/pyalarmdotcomajax/devices/__init__.py @@ -75,6 +75,12 @@ class DeviceTypeSpecificData(TypedDict, total=False): raw_recent_images: list[dict] +class UserProfile(TypedDict): + """Hold user profile fields required by devices.""" + + uses_celsius: bool + + class BaseDevice(ABC, CastingMixin): """Contains properties shared by all ADC devices.""" @@ -85,6 +91,7 @@ def __init__( config_change_callback: Callable | None, children: list[tuple[str, DeviceType]], raw_device_data: dict, + user_profile: UserProfile, device_type_specific_data: DeviceTypeSpecificData | None = None, trouble_conditions: list | None = None, partition_id: str | None = None, @@ -99,6 +106,7 @@ def __init__( ) self._settings: dict = settings if settings else {} self._partition_id: str | None = partition_id + self._user_profile: UserProfile = user_profile self.children = children self.trouble_conditions: list[TroubleCondition] = trouble_conditions if trouble_conditions else [] diff --git a/pyalarmdotcomajax/devices/thermostat.py b/pyalarmdotcomajax/devices/thermostat.py index d0bfec8..ca3714b 100644 --- a/pyalarmdotcomajax/devices/thermostat.py +++ b/pyalarmdotcomajax/devices/thermostat.py @@ -100,6 +100,7 @@ class ThermostatAttributes(BaseDevice.DeviceAttributes): inferred_mode: ( Thermostat.DeviceState | None ) # Indicates what thermostat is actually doing (cooling vs heating) if mode = auto. + uses_celsius: bool | None # Fan supports_fan_mode: bool | None supports_fan_indefinite: bool | None @@ -167,6 +168,7 @@ def attributes(self) -> ThermostatAttributes: supports_schedules=self._get_bool("supportsSchedules"), supports_schedules_smart=self._get_bool("supportsSmartSchedules"), schedule_mode=self._get_special("scheduleMode", self.ScheduleMode), + uses_celsius=self._user_profile.get("uses_celsius"), ) async def async_set_attribute(