Clean up Abode imports (#113138)
This commit is contained in:
parent
18a7f004db
commit
d33fdd3289
8 changed files with 64 additions and 47 deletions
|
@ -2,10 +2,12 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from jaraco.abode.devices.alarm import Alarm as AbodeAl
|
from jaraco.abode.devices.alarm import Alarm
|
||||||
|
|
||||||
import homeassistant.components.alarm_control_panel as alarm
|
from homeassistant.components.alarm_control_panel import (
|
||||||
from homeassistant.components.alarm_control_panel import AlarmControlPanelEntityFeature
|
AlarmControlPanelEntity,
|
||||||
|
AlarmControlPanelEntityFeature,
|
||||||
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_ALARM_ARMED_AWAY,
|
STATE_ALARM_ARMED_AWAY,
|
||||||
|
@ -29,7 +31,7 @@ async def async_setup_entry(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class AbodeAlarm(AbodeDevice, alarm.AlarmControlPanelEntity):
|
class AbodeAlarm(AbodeDevice, AlarmControlPanelEntity):
|
||||||
"""An alarm_control_panel implementation for Abode."""
|
"""An alarm_control_panel implementation for Abode."""
|
||||||
|
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
|
@ -38,7 +40,7 @@ class AbodeAlarm(AbodeDevice, alarm.AlarmControlPanelEntity):
|
||||||
AlarmControlPanelEntityFeature.ARM_HOME
|
AlarmControlPanelEntityFeature.ARM_HOME
|
||||||
| AlarmControlPanelEntityFeature.ARM_AWAY
|
| AlarmControlPanelEntityFeature.ARM_AWAY
|
||||||
)
|
)
|
||||||
_device: AbodeAl
|
_device: Alarm
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self) -> str | None:
|
def state(self) -> str | None:
|
||||||
|
|
|
@ -4,8 +4,14 @@ from __future__ import annotations
|
||||||
|
|
||||||
from typing import cast
|
from typing import cast
|
||||||
|
|
||||||
from jaraco.abode.devices.sensor import BinarySensor as ABBinarySensor
|
from jaraco.abode.devices.sensor import BinarySensor
|
||||||
from jaraco.abode.helpers import constants as CONST
|
from jaraco.abode.helpers.constants import (
|
||||||
|
TYPE_CONNECTIVITY,
|
||||||
|
TYPE_MOISTURE,
|
||||||
|
TYPE_MOTION,
|
||||||
|
TYPE_OCCUPANCY,
|
||||||
|
TYPE_OPENING,
|
||||||
|
)
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorDeviceClass,
|
BinarySensorDeviceClass,
|
||||||
|
@ -27,11 +33,11 @@ async def async_setup_entry(
|
||||||
data: AbodeSystem = hass.data[DOMAIN]
|
data: AbodeSystem = hass.data[DOMAIN]
|
||||||
|
|
||||||
device_types = [
|
device_types = [
|
||||||
CONST.TYPE_CONNECTIVITY,
|
TYPE_CONNECTIVITY,
|
||||||
CONST.TYPE_MOISTURE,
|
TYPE_MOISTURE,
|
||||||
CONST.TYPE_MOTION,
|
TYPE_MOTION,
|
||||||
CONST.TYPE_OCCUPANCY,
|
TYPE_OCCUPANCY,
|
||||||
CONST.TYPE_OPENING,
|
TYPE_OPENING,
|
||||||
]
|
]
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
|
@ -44,7 +50,7 @@ class AbodeBinarySensor(AbodeDevice, BinarySensorEntity):
|
||||||
"""A binary sensor implementation for Abode device."""
|
"""A binary sensor implementation for Abode device."""
|
||||||
|
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
_device: ABBinarySensor
|
_device: BinarySensor
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
|
|
|
@ -5,9 +5,10 @@ from __future__ import annotations
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
from jaraco.abode.devices.base import Device as AbodeDev
|
from jaraco.abode.devices.base import Device
|
||||||
from jaraco.abode.devices.camera import Camera as AbodeCam
|
from jaraco.abode.devices.camera import Camera as AbodeCam
|
||||||
from jaraco.abode.helpers import constants as CONST, timeline as TIMELINE
|
from jaraco.abode.helpers import timeline
|
||||||
|
from jaraco.abode.helpers.constants import TYPE_CAMERA
|
||||||
import requests
|
import requests
|
||||||
from requests.models import Response
|
from requests.models import Response
|
||||||
|
|
||||||
|
@ -31,8 +32,8 @@ async def async_setup_entry(
|
||||||
data: AbodeSystem = hass.data[DOMAIN]
|
data: AbodeSystem = hass.data[DOMAIN]
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
AbodeCamera(data, device, TIMELINE.CAPTURE_IMAGE)
|
AbodeCamera(data, device, timeline.CAPTURE_IMAGE)
|
||||||
for device in data.abode.get_devices(generic_type=CONST.TYPE_CAMERA)
|
for device in data.abode.get_devices(generic_type=TYPE_CAMERA)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ class AbodeCamera(AbodeDevice, Camera):
|
||||||
_device: AbodeCam
|
_device: AbodeCam
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
|
|
||||||
def __init__(self, data: AbodeSystem, device: AbodeDev, event: Event) -> None:
|
def __init__(self, data: AbodeSystem, device: Device, event: Event) -> None:
|
||||||
"""Initialize the Abode device."""
|
"""Initialize the Abode device."""
|
||||||
AbodeDevice.__init__(self, data, device)
|
AbodeDevice.__init__(self, data, device)
|
||||||
Camera.__init__(self)
|
Camera.__init__(self)
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from jaraco.abode.devices.cover import Cover as AbodeCV
|
from jaraco.abode.devices.cover import Cover
|
||||||
from jaraco.abode.helpers import constants as CONST
|
from jaraco.abode.helpers.constants import TYPE_COVER
|
||||||
|
|
||||||
from homeassistant.components.cover import CoverEntity
|
from homeassistant.components.cover import CoverEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
@ -22,14 +22,14 @@ async def async_setup_entry(
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
AbodeCover(data, device)
|
AbodeCover(data, device)
|
||||||
for device in data.abode.get_devices(generic_type=CONST.TYPE_COVER)
|
for device in data.abode.get_devices(generic_type=TYPE_COVER)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class AbodeCover(AbodeDevice, CoverEntity):
|
class AbodeCover(AbodeDevice, CoverEntity):
|
||||||
"""Representation of an Abode cover."""
|
"""Representation of an Abode cover."""
|
||||||
|
|
||||||
_device: AbodeCV
|
_device: Cover
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -5,8 +5,8 @@ from __future__ import annotations
|
||||||
from math import ceil
|
from math import ceil
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from jaraco.abode.devices.light import Light as AbodeLT
|
from jaraco.abode.devices.light import Light
|
||||||
from jaraco.abode.helpers import constants as CONST
|
from jaraco.abode.helpers.constants import TYPE_LIGHT
|
||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
|
@ -35,14 +35,14 @@ async def async_setup_entry(
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
AbodeLight(data, device)
|
AbodeLight(data, device)
|
||||||
for device in data.abode.get_devices(generic_type=CONST.TYPE_LIGHT)
|
for device in data.abode.get_devices(generic_type=TYPE_LIGHT)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class AbodeLight(AbodeDevice, LightEntity):
|
class AbodeLight(AbodeDevice, LightEntity):
|
||||||
"""Representation of an Abode light."""
|
"""Representation of an Abode light."""
|
||||||
|
|
||||||
_device: AbodeLT
|
_device: Light
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
|
|
||||||
def turn_on(self, **kwargs: Any) -> None:
|
def turn_on(self, **kwargs: Any) -> None:
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from jaraco.abode.devices.lock import Lock as AbodeLK
|
from jaraco.abode.devices.lock import Lock
|
||||||
from jaraco.abode.helpers import constants as CONST
|
from jaraco.abode.helpers.constants import TYPE_LOCK
|
||||||
|
|
||||||
from homeassistant.components.lock import LockEntity
|
from homeassistant.components.lock import LockEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
@ -22,14 +22,14 @@ async def async_setup_entry(
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
AbodeLock(data, device)
|
AbodeLock(data, device)
|
||||||
for device in data.abode.get_devices(generic_type=CONST.TYPE_LOCK)
|
for device in data.abode.get_devices(generic_type=TYPE_LOCK)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class AbodeLock(AbodeDevice, LockEntity):
|
class AbodeLock(AbodeDevice, LockEntity):
|
||||||
"""Representation of an Abode lock."""
|
"""Representation of an Abode lock."""
|
||||||
|
|
||||||
_device: AbodeLK
|
_device: Lock
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
|
|
||||||
def lock(self, **kwargs: Any) -> None:
|
def lock(self, **kwargs: Any) -> None:
|
||||||
|
|
|
@ -6,8 +6,16 @@ from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import cast
|
from typing import cast
|
||||||
|
|
||||||
from jaraco.abode.devices.sensor import Sensor as AbodeSense
|
from jaraco.abode.devices.sensor import Sensor
|
||||||
from jaraco.abode.helpers import constants as CONST
|
from jaraco.abode.helpers.constants import (
|
||||||
|
HUMI_STATUS_KEY,
|
||||||
|
LUX_STATUS_KEY,
|
||||||
|
STATUSES_KEY,
|
||||||
|
TEMP_STATUS_KEY,
|
||||||
|
TYPE_SENSOR,
|
||||||
|
UNIT_CELSIUS,
|
||||||
|
UNIT_FAHRENHEIT,
|
||||||
|
)
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
|
@ -23,8 +31,8 @@ from . import AbodeDevice, AbodeSystem
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
ABODE_TEMPERATURE_UNIT_HA_UNIT = {
|
ABODE_TEMPERATURE_UNIT_HA_UNIT = {
|
||||||
CONST.UNIT_FAHRENHEIT: UnitOfTemperature.FAHRENHEIT,
|
UNIT_FAHRENHEIT: UnitOfTemperature.FAHRENHEIT,
|
||||||
CONST.UNIT_CELSIUS: UnitOfTemperature.CELSIUS,
|
UNIT_CELSIUS: UnitOfTemperature.CELSIUS,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,13 +40,13 @@ ABODE_TEMPERATURE_UNIT_HA_UNIT = {
|
||||||
class AbodeSensorDescription(SensorEntityDescription):
|
class AbodeSensorDescription(SensorEntityDescription):
|
||||||
"""Class describing Abode sensor entities."""
|
"""Class describing Abode sensor entities."""
|
||||||
|
|
||||||
value_fn: Callable[[AbodeSense], float]
|
value_fn: Callable[[Sensor], float]
|
||||||
native_unit_of_measurement_fn: Callable[[AbodeSense], str]
|
native_unit_of_measurement_fn: Callable[[Sensor], str]
|
||||||
|
|
||||||
|
|
||||||
SENSOR_TYPES: tuple[AbodeSensorDescription, ...] = (
|
SENSOR_TYPES: tuple[AbodeSensorDescription, ...] = (
|
||||||
AbodeSensorDescription(
|
AbodeSensorDescription(
|
||||||
key=CONST.TEMP_STATUS_KEY,
|
key=TEMP_STATUS_KEY,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
native_unit_of_measurement_fn=lambda device: ABODE_TEMPERATURE_UNIT_HA_UNIT[
|
native_unit_of_measurement_fn=lambda device: ABODE_TEMPERATURE_UNIT_HA_UNIT[
|
||||||
device.temp_unit
|
device.temp_unit
|
||||||
|
@ -46,13 +54,13 @@ SENSOR_TYPES: tuple[AbodeSensorDescription, ...] = (
|
||||||
value_fn=lambda device: cast(float, device.temp),
|
value_fn=lambda device: cast(float, device.temp),
|
||||||
),
|
),
|
||||||
AbodeSensorDescription(
|
AbodeSensorDescription(
|
||||||
key=CONST.HUMI_STATUS_KEY,
|
key=HUMI_STATUS_KEY,
|
||||||
device_class=SensorDeviceClass.HUMIDITY,
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
native_unit_of_measurement_fn=lambda _: PERCENTAGE,
|
native_unit_of_measurement_fn=lambda _: PERCENTAGE,
|
||||||
value_fn=lambda device: cast(float, device.humidity),
|
value_fn=lambda device: cast(float, device.humidity),
|
||||||
),
|
),
|
||||||
AbodeSensorDescription(
|
AbodeSensorDescription(
|
||||||
key=CONST.LUX_STATUS_KEY,
|
key=LUX_STATUS_KEY,
|
||||||
device_class=SensorDeviceClass.ILLUMINANCE,
|
device_class=SensorDeviceClass.ILLUMINANCE,
|
||||||
native_unit_of_measurement_fn=lambda _: LIGHT_LUX,
|
native_unit_of_measurement_fn=lambda _: LIGHT_LUX,
|
||||||
value_fn=lambda device: cast(float, device.lux),
|
value_fn=lambda device: cast(float, device.lux),
|
||||||
|
@ -69,8 +77,8 @@ async def async_setup_entry(
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
AbodeSensor(data, device, description)
|
AbodeSensor(data, device, description)
|
||||||
for description in SENSOR_TYPES
|
for description in SENSOR_TYPES
|
||||||
for device in data.abode.get_devices(generic_type=CONST.TYPE_SENSOR)
|
for device in data.abode.get_devices(generic_type=TYPE_SENSOR)
|
||||||
if description.key in device.get_value(CONST.STATUSES_KEY)
|
if description.key in device.get_value(STATUSES_KEY)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,12 +86,12 @@ class AbodeSensor(AbodeDevice, SensorEntity):
|
||||||
"""A sensor implementation for Abode devices."""
|
"""A sensor implementation for Abode devices."""
|
||||||
|
|
||||||
entity_description: AbodeSensorDescription
|
entity_description: AbodeSensorDescription
|
||||||
_device: AbodeSense
|
_device: Sensor
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
data: AbodeSystem,
|
data: AbodeSystem,
|
||||||
device: AbodeSense,
|
device: Sensor,
|
||||||
description: AbodeSensorDescription,
|
description: AbodeSensorDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize a sensor for an Abode device."""
|
"""Initialize a sensor for an Abode device."""
|
||||||
|
|
|
@ -4,8 +4,8 @@ from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
from jaraco.abode.devices.switch import Switch as AbodeSW
|
from jaraco.abode.devices.switch import Switch
|
||||||
from jaraco.abode.helpers import constants as CONST
|
from jaraco.abode.helpers.constants import TYPE_SWITCH, TYPE_VALVE
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity
|
from homeassistant.components.switch import SwitchEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
@ -16,7 +16,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from . import AbodeAutomation, AbodeDevice, AbodeSystem
|
from . import AbodeAutomation, AbodeDevice, AbodeSystem
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
DEVICE_TYPES = [CONST.TYPE_SWITCH, CONST.TYPE_VALVE]
|
DEVICE_TYPES = [TYPE_SWITCH, TYPE_VALVE]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
@ -42,7 +42,7 @@ async def async_setup_entry(
|
||||||
class AbodeSwitch(AbodeDevice, SwitchEntity):
|
class AbodeSwitch(AbodeDevice, SwitchEntity):
|
||||||
"""Representation of an Abode switch."""
|
"""Representation of an Abode switch."""
|
||||||
|
|
||||||
_device: AbodeSW
|
_device: Switch
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
|
|
||||||
def turn_on(self, **kwargs: Any) -> None:
|
def turn_on(self, **kwargs: Any) -> None:
|
||||||
|
|
Loading…
Add table
Reference in a new issue