Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reads proper unit of measurement from thermostats. #132

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions pyalarmdotcomajax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
BaseDevice,
DeviceTypeSpecificData,
TroubleCondition,
UserProfile,
)
from pyalarmdotcomajax.devices.partition import Partition
from pyalarmdotcomajax.devices.registry import (
Expand All @@ -47,7 +48,7 @@
)
from pyalarmdotcomajax.websockets.client import WebSocketClient, WebSocketState

__version__ = "0.5.7"
__version__ = "0.5.8"

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -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__}",
Expand All @@ -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()
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions pyalarmdotcomajax/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand All @@ -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,
Expand All @@ -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 []
Expand Down
2 changes: 2 additions & 0 deletions pyalarmdotcomajax/devices/thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down