From b7dd3a53f364e995d82708425142220828b85d08 Mon Sep 17 00:00:00 2001 From: Steve Herrell <47094394+twrecked@users.noreply.github.com> Date: Fri, 8 Nov 2024 22:46:20 -0500 Subject: [PATCH] Fix deprecated constants. (#1010) --- changelog | 2 + custom_components/aarlo/__init__.py | 2 +- .../aarlo/alarm_control_panel.py | 46 +++++++++---------- custom_components/aarlo/camera.py | 16 +++---- custom_components/aarlo/cfg.py | 5 +- custom_components/aarlo/config_flow.py | 4 +- custom_components/aarlo/const.py | 1 + custom_components/aarlo/manifest.json | 2 +- custom_components/aarlo/media_player.py | 5 +- 9 files changed, 42 insertions(+), 41 deletions(-) diff --git a/changelog b/changelog index 5580db91..5ccdca4c 100644 --- a/changelog +++ b/changelog @@ -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 diff --git a/custom_components/aarlo/__init__.py b/custom_components/aarlo/__init__.py index f59395a4..3e7040c0 100644 --- a/custom_components/aarlo/__init__.py +++ b/custom_components/aarlo/__init__.py @@ -53,7 +53,7 @@ from .cfg import BlendedCfg, PyaarloCfg -__version__ = "0.8.1.8" +__version__ = "0.8.1.9" _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/aarlo/alarm_control_panel.py b/custom_components/aarlo/alarm_control_panel.py index 165c2fbf..c1b4e8a1 100644 --- a/custom_components/aarlo/alarm_control_panel.py +++ b/custom_components/aarlo/alarm_control_panel.py @@ -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 @@ -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, @@ -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}") @@ -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: @@ -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"): @@ -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 @@ -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"): diff --git a/custom_components/aarlo/camera.py b/custom_components/aarlo/camera.py index 5d933dc2..63d9c660 100644 --- a/custom_components/aarlo/camera.py +++ b/custom_components/aarlo/camera.py @@ -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, @@ -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 @@ -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 @@ -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 @@ -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" @@ -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() @@ -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}") diff --git a/custom_components/aarlo/cfg.py b/custom_components/aarlo/cfg.py index 8749dea6..380802a7 100644 --- a/custom_components/aarlo/cfg.py +++ b/custom_components/aarlo/cfg.py @@ -30,7 +30,6 @@ CONF_TRIGGER_TIME, CONF_USERNAME, Platform, - STATE_ALARM_DISARMED, UnitOfTemperature ) from homeassistant.helpers import config_validation as cv @@ -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, @@ -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, diff --git a/custom_components/aarlo/config_flow.py b/custom_components/aarlo/config_flow.py index be870684..fc07080f 100644 --- a/custom_components/aarlo/config_flow.py +++ b/custom_components/aarlo/config_flow.py @@ -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, \ @@ -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 ) @@ -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, diff --git a/custom_components/aarlo/const.py b/custom_components/aarlo/const.py index 8029511a..0ec798b6 100644 --- a/custom_components/aarlo/const.py +++ b/custom_components/aarlo/const.py @@ -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" diff --git a/custom_components/aarlo/manifest.json b/custom_components/aarlo/manifest.json index ff71e3f2..2c4baaa9 100644 --- a/custom_components/aarlo/manifest.json +++ b/custom_components/aarlo/manifest.json @@ -15,5 +15,5 @@ "unidecode", "pyaarlo>=0.8.0.12" ], - "version": "0.8.1.8" + "version": "0.8.1.9" } diff --git a/custom_components/aarlo/media_player.py b/custom_components/aarlo/media_player.py index ab804de9..44d19278 100644 --- a/custom_components/aarlo/media_player.py +++ b/custom_components/aarlo/media_player.py @@ -18,7 +18,6 @@ from homeassistant.components.media_player.const import ( MediaPlayerState, MediaType, - MEDIA_TYPE_MUSIC, ) from homeassistant.const import ( ATTR_ATTRIBUTION, @@ -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()