diff --git a/homeassistant/components/simplisafe/__init__.py b/homeassistant/components/simplisafe/__init__.py index a25f76bcbc8..404c6e96fd4 100644 --- a/homeassistant/components/simplisafe/__init__.py +++ b/homeassistant/components/simplisafe/__init__.py @@ -16,11 +16,16 @@ from simplipy.errors import ( from simplipy.system import SystemNotification from simplipy.system.v2 import SystemV2 from simplipy.system.v3 import ( - VOLUME_HIGH, - VOLUME_LOW, - VOLUME_MEDIUM, - VOLUME_OFF, + MAX_ALARM_DURATION, + MAX_ENTRY_DELAY_AWAY, + MAX_ENTRY_DELAY_HOME, + MAX_EXIT_DELAY_AWAY, + MAX_EXIT_DELAY_HOME, + MIN_ALARM_DURATION, + MIN_ENTRY_DELAY_AWAY, + MIN_EXIT_DELAY_AWAY, SystemV3, + Volume, ) from simplipy.websocket import ( EVENT_AUTOMATIC_TEST, @@ -120,10 +125,10 @@ PLATFORMS = ( ) VOLUME_MAP = { - "high": VOLUME_HIGH, - "low": VOLUME_LOW, - "medium": VOLUME_MEDIUM, - "off": VOLUME_OFF, + "high": Volume.HIGH, + "low": Volume.LOW, + "medium": Volume.MEDIUM, + "off": Volume.OFF, } SERVICE_BASE_SCHEMA = vol.Schema({vol.Required(ATTR_SYSTEM_ID): cv.positive_int}) @@ -141,25 +146,29 @@ SERVICE_SET_SYSTEM_PROPERTIES_SCHEMA = SERVICE_BASE_SCHEMA.extend( vol.Optional(ATTR_ALARM_DURATION): vol.All( cv.time_period, lambda value: value.total_seconds(), - vol.Range(min=30, max=480), + vol.Range(min=MIN_ALARM_DURATION, max=MAX_ALARM_DURATION), ), vol.Optional(ATTR_ALARM_VOLUME): vol.All(vol.In(VOLUME_MAP), VOLUME_MAP.get), vol.Optional(ATTR_CHIME_VOLUME): vol.All(vol.In(VOLUME_MAP), VOLUME_MAP.get), vol.Optional(ATTR_ENTRY_DELAY_AWAY): vol.All( cv.time_period, lambda value: value.total_seconds(), - vol.Range(min=30, max=255), + vol.Range(min=MIN_ENTRY_DELAY_AWAY, max=MAX_ENTRY_DELAY_AWAY), ), vol.Optional(ATTR_ENTRY_DELAY_HOME): vol.All( - cv.time_period, lambda value: value.total_seconds(), vol.Range(max=255) + cv.time_period, + lambda value: value.total_seconds(), + vol.Range(max=MAX_ENTRY_DELAY_HOME), ), vol.Optional(ATTR_EXIT_DELAY_AWAY): vol.All( cv.time_period, lambda value: value.total_seconds(), - vol.Range(min=45, max=255), + vol.Range(min=MIN_EXIT_DELAY_AWAY, max=MAX_EXIT_DELAY_AWAY), ), vol.Optional(ATTR_EXIT_DELAY_HOME): vol.All( - cv.time_period, lambda value: value.total_seconds(), vol.Range(max=255) + cv.time_period, + lambda value: value.total_seconds(), + vol.Range(max=MAX_EXIT_DELAY_HOME), ), vol.Optional(ATTR_LIGHT): cv.boolean, vol.Optional(ATTR_VOICE_PROMPT_VOLUME): vol.All( @@ -457,8 +466,8 @@ class SimpliSafe: assert self._api.refresh_token assert self._api.websocket - self._api.websocket.add_connect_listener(self._async_websocket_on_connect) - self._api.websocket.add_event_listener(self._async_websocket_on_event) + self._api.websocket.add_connect_callback(self._async_websocket_on_connect) + self._api.websocket.add_event_callback(self._async_websocket_on_event) asyncio.create_task(self._api.websocket.async_connect()) async def async_websocket_disconnect_listener(_: Event) -> None: @@ -510,7 +519,7 @@ class SimpliSafe: ) self.entry.async_on_unload( - self._api.add_refresh_token_listener(async_save_refresh_token) + self._api.add_refresh_token_callback(async_save_refresh_token) ) async_save_refresh_token(self._api.refresh_token) @@ -566,15 +575,16 @@ class SimpliSafeEntity(CoordinatorEntity): device_name = DEFAULT_ENTITY_NAME serial = system.serial - try: - device_type = DeviceTypes( - simplisafe.initial_event_to_use[system.system_id].get("sensorType") - ) - except ValueError: - device_type = DeviceTypes.unknown - event = simplisafe.initial_event_to_use[system.system_id] + if raw_type := event.get("sensorType"): + try: + device_type = DeviceTypes(raw_type) + except ValueError: + device_type = DeviceTypes.UNKNOWN + else: + device_type = DeviceTypes.UNKNOWN + self._attr_extra_state_attributes = { ATTR_LAST_EVENT_INFO: event.get("info"), ATTR_LAST_EVENT_SENSOR_NAME: event.get("sensorName"), diff --git a/homeassistant/components/simplisafe/alarm_control_panel.py b/homeassistant/components/simplisafe/alarm_control_panel.py index de571f1291d..7a09db18b07 100644 --- a/homeassistant/components/simplisafe/alarm_control_panel.py +++ b/homeassistant/components/simplisafe/alarm_control_panel.py @@ -6,13 +6,7 @@ from typing import TYPE_CHECKING from simplipy.errors import SimplipyError from simplipy.system import SystemStates from simplipy.system.v2 import SystemV2 -from simplipy.system.v3 import ( - VOLUME_HIGH, - VOLUME_LOW, - VOLUME_MEDIUM, - VOLUME_OFF, - SystemV3, -) +from simplipy.system.v3 import SystemV3 from simplipy.websocket import ( EVENT_ALARM_CANCELED, EVENT_ALARM_TRIGGERED, @@ -71,20 +65,13 @@ ATTR_RF_JAMMING = "rf_jamming" ATTR_WALL_POWER_LEVEL = "wall_power_level" ATTR_WIFI_STRENGTH = "wifi_strength" -VOLUME_STRING_MAP = { - VOLUME_HIGH: "high", - VOLUME_LOW: "low", - VOLUME_MEDIUM: "medium", - VOLUME_OFF: "off", -} - STATE_MAP_FROM_REST_API = { - SystemStates.alarm: STATE_ALARM_TRIGGERED, - SystemStates.away: STATE_ALARM_ARMED_AWAY, - SystemStates.away_count: STATE_ALARM_ARMING, - SystemStates.exit_delay: STATE_ALARM_ARMING, - SystemStates.home: STATE_ALARM_ARMED_HOME, - SystemStates.off: STATE_ALARM_DISARMED, + SystemStates.ALARM: STATE_ALARM_TRIGGERED, + SystemStates.AWAY: STATE_ALARM_ARMED_AWAY, + SystemStates.AWAY_COUNT: STATE_ALARM_ARMING, + SystemStates.EXIT_DELAY: STATE_ALARM_ARMING, + SystemStates.HOME: STATE_ALARM_ARMED_HOME, + SystemStates.OFF: STATE_ALARM_DISARMED, } STATE_MAP_FROM_WEBSOCKET_EVENT = { @@ -226,9 +213,9 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity): self._attr_extra_state_attributes.update( { ATTR_ALARM_DURATION: self._system.alarm_duration, - ATTR_ALARM_VOLUME: VOLUME_STRING_MAP[self._system.alarm_volume], + ATTR_ALARM_VOLUME: self._system.alarm_volume.name.lower(), ATTR_BATTERY_BACKUP_POWER_LEVEL: self._system.battery_backup_power_level, - ATTR_CHIME_VOLUME: VOLUME_STRING_MAP[self._system.chime_volume], + ATTR_CHIME_VOLUME: self._system.chime_volume.name.lower(), ATTR_ENTRY_DELAY_AWAY: self._system.entry_delay_away, ATTR_ENTRY_DELAY_HOME: self._system.entry_delay_home, ATTR_EXIT_DELAY_AWAY: self._system.exit_delay_away, @@ -236,9 +223,7 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity): ATTR_GSM_STRENGTH: self._system.gsm_strength, ATTR_LIGHT: self._system.light, ATTR_RF_JAMMING: self._system.rf_jamming, - ATTR_VOICE_PROMPT_VOLUME: VOLUME_STRING_MAP[ - self._system.voice_prompt_volume - ], + ATTR_VOICE_PROMPT_VOLUME: self._system.voice_prompt_volume.name.lower(), ATTR_WALL_POWER_LEVEL: self._system.wall_power_level, ATTR_WIFI_STRENGTH: self._system.wifi_strength, } diff --git a/homeassistant/components/simplisafe/binary_sensor.py b/homeassistant/components/simplisafe/binary_sensor.py index eef38ffe003..240ff24c6c8 100644 --- a/homeassistant/components/simplisafe/binary_sensor.py +++ b/homeassistant/components/simplisafe/binary_sensor.py @@ -24,25 +24,25 @@ from . import SimpliSafe, SimpliSafeEntity from .const import DOMAIN, LOGGER SUPPORTED_BATTERY_SENSOR_TYPES = [ - DeviceTypes.carbon_monoxide, - DeviceTypes.entry, - DeviceTypes.glass_break, - DeviceTypes.leak, - DeviceTypes.lock_keypad, - DeviceTypes.motion, - DeviceTypes.siren, - DeviceTypes.smoke, - DeviceTypes.temperature, + DeviceTypes.CARBON_MONOXIDE, + DeviceTypes.ENTRY, + DeviceTypes.GLASS_BREAK, + DeviceTypes.LEAK, + DeviceTypes.LOCK_KEYPAD, + DeviceTypes.MOTION, + DeviceTypes.SIREN, + DeviceTypes.SMOKE, + DeviceTypes.TEMPERATURE, ] TRIGGERED_SENSOR_TYPES = { - DeviceTypes.carbon_monoxide: DEVICE_CLASS_GAS, - DeviceTypes.entry: DEVICE_CLASS_DOOR, - DeviceTypes.glass_break: DEVICE_CLASS_SAFETY, - DeviceTypes.leak: DEVICE_CLASS_MOISTURE, - DeviceTypes.motion: DEVICE_CLASS_MOTION, - DeviceTypes.siren: DEVICE_CLASS_SAFETY, - DeviceTypes.smoke: DEVICE_CLASS_SMOKE, + DeviceTypes.CARBON_MONOXIDE: DEVICE_CLASS_GAS, + DeviceTypes.ENTRY: DEVICE_CLASS_DOOR, + DeviceTypes.GLASS_BREAK: DEVICE_CLASS_SAFETY, + DeviceTypes.LEAK: DEVICE_CLASS_MOISTURE, + DeviceTypes.MOTION: DEVICE_CLASS_MOTION, + DeviceTypes.SIREN: DEVICE_CLASS_SAFETY, + DeviceTypes.SMOKE: DEVICE_CLASS_SMOKE, } diff --git a/homeassistant/components/simplisafe/lock.py b/homeassistant/components/simplisafe/lock.py index 263fd54f9d6..12d06c1028a 100644 --- a/homeassistant/components/simplisafe/lock.py +++ b/homeassistant/components/simplisafe/lock.py @@ -90,6 +90,9 @@ class SimpliSafeLock(SimpliSafeEntity, LockEntity): @callback def async_update_from_rest_api(self) -> None: """Update the entity with the provided REST API data.""" + self._attr_is_jammed = self._device.state == LockStates.JAMMED + self._attr_is_locked = self._device.state == LockStates.LOCKED + self._attr_extra_state_attributes.update( { ATTR_LOCK_LOW_BATTERY: self._device.lock_low_battery, @@ -97,9 +100,6 @@ class SimpliSafeLock(SimpliSafeEntity, LockEntity): } ) - self._attr_is_jammed = self._device.state == LockStates.jammed - self._attr_is_locked = self._device.state == LockStates.locked - @callback def async_update_from_websocket_event(self, event: WebsocketEvent) -> None: """Update the entity when new data comes from the websocket.""" diff --git a/homeassistant/components/simplisafe/manifest.json b/homeassistant/components/simplisafe/manifest.json index 97968e124b1..ecc4578d878 100644 --- a/homeassistant/components/simplisafe/manifest.json +++ b/homeassistant/components/simplisafe/manifest.json @@ -3,7 +3,7 @@ "name": "SimpliSafe", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/simplisafe", - "requirements": ["simplisafe-python==12.0.2"], + "requirements": ["simplisafe-python==2021.11.0"], "codeowners": ["@bachya"], "iot_class": "cloud_polling", "dhcp": [ diff --git a/homeassistant/components/simplisafe/sensor.py b/homeassistant/components/simplisafe/sensor.py index 0fb9c129a7c..b2b0a432bd6 100644 --- a/homeassistant/components/simplisafe/sensor.py +++ b/homeassistant/components/simplisafe/sensor.py @@ -28,7 +28,7 @@ async def async_setup_entry( continue for sensor in system.sensors.values(): - if sensor.type == DeviceTypes.temperature: + if sensor.type == DeviceTypes.TEMPERATURE: sensors.append(SimplisafeFreezeSensor(simplisafe, system, sensor)) async_add_entities(sensors) diff --git a/requirements_all.txt b/requirements_all.txt index cf1f2f7a6dd..5f47b64934e 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2143,7 +2143,7 @@ simplehound==0.3 simplepush==1.1.4 # homeassistant.components.simplisafe -simplisafe-python==12.0.2 +simplisafe-python==2021.11.0 # homeassistant.components.sisyphus sisyphus-control==3.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index bceeb3d283a..62a484980f9 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1257,7 +1257,7 @@ sharkiqpy==0.1.8 simplehound==0.3 # homeassistant.components.simplisafe -simplisafe-python==12.0.2 +simplisafe-python==2021.11.0 # homeassistant.components.slack slackclient==2.5.0