Skip to content

Commit

Permalink
Merge pull request #809 from jnewland/renovate/uvjustin-alarmdotcom-3.x
Browse files Browse the repository at this point in the history
chore(deps): update dependency uvjustin/alarmdotcom to v3.0.9
  • Loading branch information
jnewland authored Oct 27, 2023
2 parents 7bda558 + 173ec8f commit dc2acf6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 36 deletions.
5 changes: 2 additions & 3 deletions custom_components/alarmdotcom/base_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
ATTRIB_BATTERY_NORMAL,
DEVICE_STATIC_ATTRIBUTES,
DOMAIN,
EVENT_LISTENER_BASE_DEVICE,
)
from .controller import AlarmIntegrationController

Expand Down Expand Up @@ -70,7 +69,7 @@ def device_type_name(self) -> str:
async def async_added_to_hass(self) -> None:
"""Register callbacks."""

self._device.register_external_update_callback(self._update_device_data, EVENT_LISTENER_BASE_DEVICE)
self._device.register_external_update_callback(self._update_device_data, self.name)

self._update_device_data()

Expand All @@ -81,7 +80,7 @@ async def async_will_remove_from_hass(self) -> None:

# This will fail for devices that were removed from ADC during this session.
with contextlib.suppress(ValueError):
self._device.unregister_external_update_callback(self._update_device_data, EVENT_LISTENER_BASE_DEVICE)
self._device.unregister_external_update_callback(self._update_device_data, self.name)

await super().async_will_remove_from_hass()

Expand Down
9 changes: 6 additions & 3 deletions custom_components/alarmdotcom/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
FAN_ON,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_FAHRENHEIT
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.helpers.entity_platform import AddEntitiesCallback, DiscoveryInfoType
from pyalarmdotcomajax.devices.registry import AllDevices_t
from pyalarmdotcomajax.devices.thermostat import Thermostat as libThermostat
Expand Down Expand Up @@ -58,8 +58,6 @@ class Climate(HardwareBaseDevice, ClimateEntity): # type: ignore
_device_type_name: str = "Thermostat"
_device: libThermostat

_attr_temperature_unit = TEMP_FAHRENHEIT # Alarm.com always returns Fahrenheit, even when user profile is set to C. Conversion happens on frontend.

_raw_attribs: libThermostat.ThermostatAttributes

def __init__(
Expand Down Expand Up @@ -223,6 +221,11 @@ async def async_set_temperature(self, **kwargs) -> None: # type: ignore

def _determine_features(self) -> None:
"""Determine which features are available for thermostat."""
#
# UNIT OF MEASUREMENT
#

self._attr_temperature_unit = TEMP_CELSIUS if self._device.attributes.uses_celsius else TEMP_FAHRENHEIT

#
# SUPPORTED FEATURES
Expand Down
2 changes: 0 additions & 2 deletions custom_components/alarmdotcom/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@

DATA_CONTROLLER = "connection"

EVENT_LISTENER_BASE_DEVICE = "Device Controller"

ATTRIB_BATTERY_NORMAL = "Normal"
ATTRIB_BATTERY_LOW = "Low"
ATTRIB_BATTERY_CRITICAL = "Critical"
Expand Down
56 changes: 31 additions & 25 deletions custom_components/alarmdotcom/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,41 +61,23 @@ def __init__(

self._attr_color_mode = light.COLOR_MODE_BRIGHTNESS if self._device.brightness else light.COLOR_MODE_ONOFF

self._attr_assumed_state = self._device.supports_state_tracking is True
self._attr_assumed_state = self._device.supports_state_tracking is False

# Independently track state for lights that don't support state tracking
self._local_state: bool | None = None
self._local_brightness: int | None = None

@property
def is_on(self) -> bool | None:
"""Return True if entity is on."""

# LOGGER.info(
# "Processing state %s for %s",
# self._device.state,
# self.name or self._device.name,
# )

if not self._device.malfunction:
match self._device.state:
case libLight.DeviceState.ON | libLight.DeviceState.LEVELCHANGE:
return True

case libLight.DeviceState.OFF:
return False

LOGGER.exception(
"Cannot determine light state. Found raw state of %s.",
self._device.state,
)

return None
return self._local_state

@property
def brightness(self) -> int | None:
"""Return the brightness of the light."""

if raw_bright := self._device.brightness:
return int((raw_bright * 255) / 100)

return None
return self._local_brightness

async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the light or adjust brightness."""
Expand All @@ -109,10 +91,34 @@ async def async_turn_on(self, **kwargs: Any) -> None:
except NotAuthorized:
self._show_permission_error("turn on or adjust brightness on")

if self.assumed_state:
# optimistically assume that light has changed state
self._local_state = True
self._local_brightness = kwargs.get(ATTR_BRIGHTNESS)

async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn off the light."""

try:
await self._device.async_turn_off()
except NotAuthorized:
self._show_permission_error("turn off")

if self.assumed_state:
# optimistically assume that light has changed state
self._local_state = False
self._local_brightness = None

def _legacy_refresh_attributes(self) -> None:
"""Perform action whenever device is updated."""

# Update state
if not self._device.malfunction and not self.assumed_state:
match self._device.state:
case libLight.DeviceState.ON | libLight.DeviceState.LEVELCHANGE:
self._local_state = True

case libLight.DeviceState.OFF:
self._local_state = False

self._local_brightness = (self._device.brightness * 255) / 100 if self._device.brightness else None
4 changes: 2 additions & 2 deletions custom_components/alarmdotcom/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"integration_type": "hub",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/pyalarmdotcom/alarmdotcom/issues",
"requirements": ["beautifulsoup4>=4.10.0", "pyalarmdotcomajax==0.5.6"],
"version": "3.0.7"
"requirements": ["beautifulsoup4>=4.10.0", "pyalarmdotcomajax==0.5.8"],
"version": "3.0.9"
}
2 changes: 1 addition & 1 deletion script/sync-components
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ rm -rf custom_components/plant || true
mv $TMPDIR/$$-homeassistant-plant/custom_components/plant custom_components

# renovate: datasource=github-releases depName=uvjustin/alarmdotcom
ALARM_DOT_COM_VERSION=v3.0.7
ALARM_DOT_COM_VERSION=v3.0.9
git clone --depth 1 --branch $ALARM_DOT_COM_VERSION https://github.com/uvjustin/alarmdotcom $TMPDIR/$$-alarmdotcom
rm -rf custom_components/alarmdotcom || true
mv $TMPDIR/$$-alarmdotcom/custom_components/alarmdotcom custom_components
Expand Down

0 comments on commit dc2acf6

Please sign in to comment.