Fix missing/incorrect SimpliSafe entities (#42846)

* Entity types

* Don't overdo it

* Fix missing/incorrect SimpliSafe entities
This commit is contained in:
Aaron Bach 2020-11-04 18:59:54 -07:00 committed by Paulus Schoutsen
parent 943cc243b5
commit 7c084975b7
2 changed files with 22 additions and 4 deletions

View File

@ -3,6 +3,7 @@ import asyncio
from uuid import UUID from uuid import UUID
from simplipy import API from simplipy import API
from simplipy.entity import EntityTypes
from simplipy.errors import EndpointUnavailable, InvalidCredentialsError, SimplipyError from simplipy.errors import EndpointUnavailable, InvalidCredentialsError, SimplipyError
from simplipy.websocket import ( from simplipy.websocket import (
EVENT_CAMERA_MOTION_DETECTED, EVENT_CAMERA_MOTION_DETECTED,
@ -590,6 +591,13 @@ class SimpliSafeEntity(CoordinatorEntity):
else: else:
self._serial = system.serial self._serial = system.serial
try:
sensor_type = EntityTypes(
simplisafe.initial_event_to_use[system.system_id].get("sensorType")
)
except ValueError:
sensor_type = EntityTypes.unknown
self._attrs = { self._attrs = {
ATTR_LAST_EVENT_INFO: simplisafe.initial_event_to_use[system.system_id].get( ATTR_LAST_EVENT_INFO: simplisafe.initial_event_to_use[system.system_id].get(
"info" "info"
@ -597,9 +605,7 @@ class SimpliSafeEntity(CoordinatorEntity):
ATTR_LAST_EVENT_SENSOR_NAME: simplisafe.initial_event_to_use[ ATTR_LAST_EVENT_SENSOR_NAME: simplisafe.initial_event_to_use[
system.system_id system.system_id
].get("sensorName"), ].get("sensorName"),
ATTR_LAST_EVENT_SENSOR_TYPE: simplisafe.initial_event_to_use[ ATTR_LAST_EVENT_SENSOR_TYPE: sensor_type.name,
system.system_id
].get("sensorType"),
ATTR_LAST_EVENT_TIMESTAMP: simplisafe.initial_event_to_use[ ATTR_LAST_EVENT_TIMESTAMP: simplisafe.initial_event_to_use[
system.system_id system.system_id
].get("eventTimestamp"), ].get("eventTimestamp"),
@ -736,3 +742,11 @@ class SimpliSafeBaseSensor(SimpliSafeEntity):
self._device_info["model"] = sensor.type.name self._device_info["model"] = sensor.type.name
self._device_info["name"] = sensor.name self._device_info["name"] = sensor.name
self._sensor = sensor self._sensor = sensor
self._sensor_type_human_name = " ".join(
[w.title() for w in self._sensor.type.name.split("_")]
)
@property
def name(self):
"""Return the name of the sensor."""
return f"{self._system.address} {self._name} {self._sensor_type_human_name}"

View File

@ -6,6 +6,8 @@ from homeassistant.components.binary_sensor import (
DEVICE_CLASS_DOOR, DEVICE_CLASS_DOOR,
DEVICE_CLASS_GAS, DEVICE_CLASS_GAS,
DEVICE_CLASS_MOISTURE, DEVICE_CLASS_MOISTURE,
DEVICE_CLASS_MOTION,
DEVICE_CLASS_SAFETY,
DEVICE_CLASS_SMOKE, DEVICE_CLASS_SMOKE,
BinarySensorEntity, BinarySensorEntity,
) )
@ -18,7 +20,7 @@ SUPPORTED_BATTERY_SENSOR_TYPES = [
EntityTypes.carbon_monoxide, EntityTypes.carbon_monoxide,
EntityTypes.entry, EntityTypes.entry,
EntityTypes.leak, EntityTypes.leak,
EntityTypes.lock, EntityTypes.lock_keypad,
EntityTypes.smoke, EntityTypes.smoke,
EntityTypes.temperature, EntityTypes.temperature,
] ]
@ -26,7 +28,9 @@ SUPPORTED_BATTERY_SENSOR_TYPES = [
TRIGGERED_SENSOR_TYPES = { TRIGGERED_SENSOR_TYPES = {
EntityTypes.carbon_monoxide: DEVICE_CLASS_GAS, EntityTypes.carbon_monoxide: DEVICE_CLASS_GAS,
EntityTypes.entry: DEVICE_CLASS_DOOR, EntityTypes.entry: DEVICE_CLASS_DOOR,
EntityTypes.glass_break: DEVICE_CLASS_SAFETY,
EntityTypes.leak: DEVICE_CLASS_MOISTURE, EntityTypes.leak: DEVICE_CLASS_MOISTURE,
EntityTypes.motion: DEVICE_CLASS_MOTION,
EntityTypes.smoke: DEVICE_CLASS_SMOKE, EntityTypes.smoke: DEVICE_CLASS_SMOKE,
} }