Skip to content

Commit

Permalink
Fix deprecated constants. (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
twrecked authored Nov 9, 2024
1 parent e00fe96 commit b7dd3a5
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 41 deletions.
2 changes: 2 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
aarlo
0.8.1.9
Remove deprecated constants.
0.8.1.8
Bump pyaarlo version to squash browser not trusted error.
0.8.1.7
Expand Down
2 changes: 1 addition & 1 deletion custom_components/aarlo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from .cfg import BlendedCfg, PyaarloCfg


__version__ = "0.8.1.8"
__version__ = "0.8.1.9"

_LOGGER = logging.getLogger(__name__)

Expand Down
46 changes: 23 additions & 23 deletions custom_components/aarlo/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@
AlarmControlPanelEntityFeature,
CodeFormat
)
from homeassistant.components.alarm_control_panel.const import (
AlarmControlPanelState
)
from homeassistant.const import (
ATTR_ATTRIBUTION,
ATTR_ENTITY_ID,
CONF_CODE,
CONF_TRIGGER_TIME,
STATE_ALARM_ARMED_AWAY,
STATE_ALARM_ARMED_HOME,
STATE_ALARM_ARMED_NIGHT,
STATE_ALARM_DISARMED,
STATE_ALARM_TRIGGERED,
)
from homeassistant.core import HomeAssistant, HassJob
from homeassistant.exceptions import HomeAssistantError
Expand All @@ -56,7 +54,7 @@
vol.Optional(CONF_CODE_ARM_REQUIRED, default=True): cv.boolean,
vol.Optional(CONF_CODE_DISARM_REQUIRED, default=True): cv.boolean,
vol.Optional(CONF_COMMAND_TEMPLATE, default=DEFAULT_COMMAND_TEMPLATE): cv.template,
vol.Optional(CONF_DISARMED_MODE_NAME, default=STATE_ALARM_DISARMED): cv.string,
vol.Optional(CONF_DISARMED_MODE_NAME, default=AlarmControlPanelState.DISARMED): cv.string,
vol.Optional(CONF_HOME_MODE_NAME, default=STATE_ALARM_ARLO_HOME): cv.string,
vol.Optional(CONF_AWAY_MODE_NAME, default=STATE_ALARM_ARLO_ARMED): cv.string,
vol.Optional(CONF_NIGHT_MODE_NAME, default=STATE_ALARM_ARLO_NIGHT): cv.string,
Expand Down Expand Up @@ -220,7 +218,6 @@ def __init__(self, device, aarlo_config, config):
self._alarm_volume = config.get(CONF_ALARM_VOLUME)
self._trigger_time = config.get(CONF_TRIGGER_TIME)
self._trigger_till = None
self._attr_state = None
self._code = config.get(CONF_CODE)
self._timer = None
_LOGGER.debug(f"alarm-code={self._code}")
Expand Down Expand Up @@ -250,15 +247,15 @@ def _get_state_from_ha(self, mode):
"""Convert Arlo mode to Home Assistant state."""
lmode = mode.lower()
if lmode == self._disarmed_mode_name:
return STATE_ALARM_DISARMED
return AlarmControlPanelState.DISARMED
if lmode == self._away_mode_name:
return STATE_ALARM_ARMED_AWAY
return AlarmControlPanelState.ARMED_AWAY
if lmode == self._home_mode_name:
return STATE_ALARM_ARMED_HOME
return AlarmControlPanelState.ARMED_HOME
if lmode == self._night_mode_name:
return STATE_ALARM_ARMED_NIGHT
return AlarmControlPanelState.ARMED_NIGHT
if lmode == STATE_ALARM_ARLO_ARMED:
return STATE_ALARM_ARMED_AWAY
return AlarmControlPanelState.ARMED_AWAY
return mode

async def _async_stop_trigger(self, *_args: Any) -> None:
Expand All @@ -273,18 +270,18 @@ async def async_added_to_hass(self):

def update_state(_device, _attr, _value):
_LOGGER.debug("callback:{self._attr_name}:{attr}:{str(value)}")
self._attr_state = self._get_state_from_ha(self._base.attribute(MODE_KEY))
self._attr_alarm_state = self._get_state_from_ha(self._base.attribute(MODE_KEY))
self.schedule_update_ha_state()

self._attr_state = self._get_state_from_ha(self._base.attribute(MODE_KEY, STATE_ALARM_ARLO_ARMED))
self._attr_alarm_state = self._get_state_from_ha(self._base.attribute(MODE_KEY, STATE_ALARM_ARLO_ARMED))
self._base.add_attr_callback(MODE_KEY, update_state)

@property
def state(self):
def alarm_state(self) -> AlarmControlPanelState | None:
"""Return the state of the device."""
if self._trigger_till is not None:
return STATE_ALARM_TRIGGERED
return self._attr_state
return AlarmControlPanelState.TRIGGERED
return self._attr_alarm_state

def alarm_disarm(self, code=None):
if self._attr_code_disarm_required and not _code_validate(self._code, code, "disarming"):
Expand Down Expand Up @@ -382,7 +379,6 @@ def __init__(self, location, aarlo_config, config):

self._location = location

self._attr_state = None
self._code = config.get(CONF_CODE)

self._attr_name = location.name
Expand All @@ -409,22 +405,26 @@ def _get_state_from_ha(self, mode):
"""Convert Arlo mode to Home Assistant state."""
_LOGGER.info(f"{self._attr_name}: mode check: mode={mode}")
if self._location.is_armed_away:
return STATE_ALARM_ARMED_AWAY
return AlarmControlPanelState.ARMED_AWAY
if self._location.is_armed_home:
return STATE_ALARM_ARMED_HOME
return STATE_ALARM_DISARMED
return AlarmControlPanelState.ARMED_HOME
return AlarmControlPanelState.DISARMED

async def async_added_to_hass(self):
"""Register callbacks."""

def update_state(_device, attr, value):
_LOGGER.debug(f"callback:{self._attr_name}:{attr}:{str(value)}")
self._attr_state = self._get_state_from_ha(self._location.attribute(MODE_KEY))
self._attr_alarm_state = self._get_state_from_ha(self._location.attribute(MODE_KEY))
self.schedule_update_ha_state()

self._attr_state = self._get_state_from_ha(self._location.attribute(MODE_KEY, "Stand By"))
self._attr_alarm_state = self._get_state_from_ha(self._location.attribute(MODE_KEY, "Stand By"))
self._location.add_attr_callback(MODE_KEY, update_state)

@property
def alarm_state(self) -> AlarmControlPanelState | None:
return self._attr_alarm_state

def alarm_disarm(self, code=None):
_LOGGER.debug(f"Location {self._attr_name} disarm. Code: {code}")
if self._attr_code_disarm_required and not _code_validate(self._code, code, "disarming"):
Expand Down
16 changes: 8 additions & 8 deletions custom_components/aarlo/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

import homeassistant.helpers.config_validation as cv
from homeassistant.components import websocket_api
from homeassistant.components.camera.const import (
CameraState
)
from homeassistant.components.camera import (
ATTR_FILENAME,
CONF_DURATION,
Expand All @@ -24,9 +27,6 @@
CameraEntityFeature,
DOMAIN as CAMERA_DOMAIN,
SERVICE_RECORD,
STATE_IDLE,
STATE_RECORDING,
STATE_STREAMING,
StreamType
)
from homeassistant.components.ffmpeg import DATA_FFMPEG
Expand All @@ -35,7 +35,6 @@
ATTR_BATTERY_LEVEL,
ATTR_ENTITY_ID,
CONF_FILENAME,
STATE_ALARM_DISARMED
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
Expand Down Expand Up @@ -72,6 +71,7 @@
CONF_SAVE_UPDATES_TO,
CONF_STREAM_SNAPSHOT,
STATE_ALARM_ARLO_ARMED,
STATE_ALARM_ARLO_DISARMED,
)
from .utils import get_entity_from_domain

Expand Down Expand Up @@ -345,10 +345,10 @@ def update_state(_device, attr, value):
self._state = "Offline, Too Cold"
self.clear_stream()
elif value == "userStreamActive":
self._state = STATE_STREAMING
self._state = CameraState.STREAMING
self._attr_is_streaming = True
elif value == "alertStreamActive":
self._state = STATE_RECORDING
self._state = CameraState.RECORDING
self._attr_is_recording = True
elif value == "unavailable":
self._state = "Unavailable"
Expand All @@ -358,7 +358,7 @@ def update_state(_device, attr, value):
elif value == "startUserStream":
pass
else:
self._state = STATE_IDLE
self._state = CameraState.IDLE
self._attr_is_streaming = False
self._attr_is_recording = False
self.clear_stream()
Expand Down Expand Up @@ -575,7 +575,7 @@ def enable_motion_detection(self):
def disable_motion_detection(self):
"""Disable the motion detection in base station (Disarm)."""
self._attr_motion_detection_enabled = False
self.set_base_station_mode(STATE_ALARM_DISARMED)
self.set_base_station_mode(STATE_ALARM_ARLO_DISARMED)

def _attach_hidden_stream(self, duration):
_LOGGER.info(f"{self._attr_unique_id} attaching hidden stream for duration {duration}")
Expand Down
5 changes: 2 additions & 3 deletions custom_components/aarlo/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
CONF_TRIGGER_TIME,
CONF_USERNAME,
Platform,
STATE_ALARM_DISARMED,
UnitOfTemperature
)
from homeassistant.helpers import config_validation as cv
Expand Down Expand Up @@ -176,7 +175,7 @@
vol.Optional(CONF_CODE_ARM_REQUIRED, default=True): cv.boolean,
vol.Optional(CONF_CODE_DISARM_REQUIRED, default=True): cv.boolean,
vol.Optional(CONF_COMMAND_TEMPLATE, default=DEFAULT_COMMAND_TEMPLATE): cv.string,
vol.Optional(CONF_DISARMED_MODE_NAME, default=STATE_ALARM_DISARMED): cv.string,
vol.Optional(CONF_DISARMED_MODE_NAME, default=STATE_ALARM_ARLO_DISARMED): cv.string,
vol.Optional(CONF_HOME_MODE_NAME, default=STATE_ALARM_ARLO_HOME): cv.string,
vol.Optional(CONF_AWAY_MODE_NAME, default=STATE_ALARM_ARLO_ARMED): cv.string,
vol.Optional(CONF_NIGHT_MODE_NAME, default=STATE_ALARM_ARLO_NIGHT): cv.string,
Expand Down Expand Up @@ -243,7 +242,7 @@
})

DEFAULT_OPTIONS = {
"alarm_control_panel_disarmed_mode_name": STATE_ALARM_DISARMED,
"alarm_control_panel_disarmed_mode_name": STATE_ALARM_ARLO_DISARMED,
"alarm_control_panel_home_mode_name": STATE_ALARM_ARLO_HOME,
"alarm_control_panel_away_mode_name": STATE_ALARM_ARLO_ARMED,
"alarm_control_panel_night_mode_name": STATE_ALARM_ARLO_NIGHT,
Expand Down
4 changes: 2 additions & 2 deletions custom_components/aarlo/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from homeassistant.const import (
CONF_PASSWORD,
CONF_USERNAME,
STATE_ALARM_DISARMED
)
from homeassistant.core import callback
from homeassistant.helpers.selector import SelectOptionDict, \
Expand All @@ -24,6 +23,7 @@
CONF_TFA_USERNAME,
COMPONENT_DOMAIN,
STATE_ALARM_ARLO_ARMED,
STATE_ALARM_ARLO_DISARMED,
STATE_ALARM_ARLO_HOME,
STATE_ALARM_ARLO_NIGHT
)
Expand Down Expand Up @@ -208,7 +208,7 @@ async def async_step_alarm_control_panel(
default=options.get("alarm_control_panel_code", "no code needed")): str,
vol.Optional("alarm_control_panel_disarmed_mode_name",
default=options.get("alarm_control_panel_disarmed_mode_name",
STATE_ALARM_DISARMED)): str,
STATE_ALARM_ARLO_DISARMED)): str,
vol.Optional("alarm_control_panel_home_mode_name",
default=options.get("alarm_control_panel_home_mode_name",
STATE_ALARM_ARLO_HOME)): str,
Expand Down
1 change: 1 addition & 0 deletions custom_components/aarlo/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
ATTR_CHARGER_TYPE = "charger_type"

# Alarm Specifics
STATE_ALARM_ARLO_DISARMED = "disarmed"
STATE_ALARM_ARLO_ARMED = "armed"
STATE_ALARM_ARLO_HOME = "home"
STATE_ALARM_ARLO_NIGHT = "night"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/aarlo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"unidecode",
"pyaarlo>=0.8.0.12"
],
"version": "0.8.1.8"
"version": "0.8.1.9"
}
5 changes: 2 additions & 3 deletions custom_components/aarlo/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from homeassistant.components.media_player.const import (
MediaPlayerState,
MediaType,
MEDIA_TYPE_MUSIC,
)
from homeassistant.const import (
ATTR_ATTRIBUTION,
Expand Down Expand Up @@ -197,11 +196,11 @@ def media_pause(self):

def play_media(self, media_type, media_id, **kwargs):
"""Play media from a URL or file."""
if not media_type == MEDIA_TYPE_MUSIC:
if not media_type == MediaType.MUSIC:
_LOGGER.error(
"Invalid media type %s. Only %s is supported",
media_type,
MEDIA_TYPE_MUSIC,
MediaType.MUSIC,
)
return
self._device.play_track()
Expand Down

0 comments on commit b7dd3a5

Please sign in to comment.