Skip to content

Commit

Permalink
Enums from HA
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Dec 13, 2021
1 parent ea86e53 commit 7e42c28
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 38 deletions.
45 changes: 18 additions & 27 deletions custom_components/jablotron100/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
from __future__ import annotations
from homeassistant import config_entries, core
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
DEVICE_CLASS_CONNECTIVITY,
DEVICE_CLASS_DOOR,
DEVICE_CLASS_GARAGE_DOOR,
DEVICE_CLASS_GAS,
DEVICE_CLASS_LOCK,
DEVICE_CLASS_MOISTURE,
DEVICE_CLASS_MOTION,
DEVICE_CLASS_PROBLEM,
DEVICE_CLASS_SMOKE,
DEVICE_CLASS_TAMPER,
DEVICE_CLASS_WINDOW,
)
from homeassistant.helpers.entity import EntityCategory
from homeassistant.const import (
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_ON,
)

from typing import Final
from .const import (
DATA_JABLOTRON,
Expand All @@ -40,15 +31,15 @@
from .jablotron import Jablotron, JablotronDevice, JablotronEntity

DEVICE_CLASSES: Final = {
DEVICE_MOTION_DETECTOR: DEVICE_CLASS_MOTION,
DEVICE_WINDOW_OPENING_DETECTOR: DEVICE_CLASS_WINDOW,
DEVICE_DOOR_OPENING_DETECTOR: DEVICE_CLASS_DOOR,
DEVICE_GARAGE_DOOR_OPENING_DETECTOR: DEVICE_CLASS_GARAGE_DOOR,
DEVICE_FLOOD_DETECTOR: DEVICE_CLASS_MOISTURE,
DEVICE_GAS_DETECTOR: DEVICE_CLASS_GAS,
DEVICE_SMOKE_DETECTOR: DEVICE_CLASS_SMOKE,
DEVICE_LOCK: DEVICE_CLASS_LOCK,
DEVICE_TAMPER: DEVICE_CLASS_TAMPER,
DEVICE_MOTION_DETECTOR: BinarySensorDeviceClass.MOTION,
DEVICE_WINDOW_OPENING_DETECTOR: BinarySensorDeviceClass.WINDOW,
DEVICE_DOOR_OPENING_DETECTOR: BinarySensorDeviceClass.DOOR,
DEVICE_GARAGE_DOOR_OPENING_DETECTOR: BinarySensorDeviceClass.GARAGE_DOOR,
DEVICE_FLOOD_DETECTOR: BinarySensorDeviceClass.MOISTURE,
DEVICE_GAS_DETECTOR: BinarySensorDeviceClass.GAS,
DEVICE_SMOKE_DETECTOR: BinarySensorDeviceClass.SMOKE,
DEVICE_LOCK: BinarySensorDeviceClass.LOCK,
DEVICE_TAMPER: BinarySensorDeviceClass.TAMPER,
}


Expand Down Expand Up @@ -79,8 +70,8 @@ def _update_attributes(self) -> None:

class JablotronProblemSensorEntity(JablotronBinarySensor):

_attr_device_class = DEVICE_CLASS_PROBLEM
_attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC
_attr_device_class = BinarySensorDeviceClass.PROBLEM
_attr_entity_category = EntityCategory.DIAGNOSTIC


class JablotronDeviceSensorEntity(JablotronBinarySensor):
Expand Down Expand Up @@ -112,14 +103,14 @@ def _update_attributes(self) -> None:

class JablotronLanConnectionEntity(JablotronBinarySensor):

_attr_device_class = DEVICE_CLASS_CONNECTIVITY
_attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC
_attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
_attr_entity_category = EntityCategory.DIAGNOSTIC


class JablotronGsmSignalEntity(JablotronBinarySensor):

_attr_device_class = DEVICE_CLASS_CONNECTIVITY
_attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC
_attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
_attr_entity_category = EntityCategory.DIAGNOSTIC

def _update_attributes(self) -> None:
super()._update_attributes()
Expand Down
17 changes: 8 additions & 9 deletions custom_components/jablotron100/sensor.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from homeassistant import config_entries, core
from homeassistant.components.sensor import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_SIGNAL_STRENGTH,
SensorDeviceClass,
SensorEntity,
STATE_CLASS_MEASUREMENT,
SensorStateClass,
)
from homeassistant.const import (
ENTITY_CATEGORY_DIAGNOSTIC,
PERCENTAGE,
)
from homeassistant.helpers.entity import EntityCategory
from .const import (
DATA_JABLOTRON,
DOMAIN,
Expand All @@ -30,7 +29,7 @@ async def async_setup_entry(hass: core.HomeAssistant, config_entry: config_entri
class JablotronSensor(JablotronEntity, SensorEntity):

_attr_native_unit_of_measurement = PERCENTAGE
_attr_state_class = STATE_CLASS_MEASUREMENT
_attr_state_class = SensorStateClass.MEASUREMENT

def _update_attributes(self) -> None:
super()._update_attributes()
Expand All @@ -40,11 +39,11 @@ def _update_attributes(self) -> None:

class JablotronSignalStrengthEntity(JablotronSensor):

_attr_device_class = DEVICE_CLASS_SIGNAL_STRENGTH
_attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC
_attr_device_class = SensorDeviceClass.SIGNAL_STRENGTH
_attr_entity_category = EntityCategory.DIAGNOSTIC


class JablotronBatteryLevelEntity(JablotronSensor):

_attr_device_class = DEVICE_CLASS_BATTERY
_attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC
_attr_device_class = SensorDeviceClass.BATTERY
_attr_entity_category = EntityCategory.DIAGNOSTIC
7 changes: 5 additions & 2 deletions custom_components/jablotron100/switch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from homeassistant import config_entries, core
from homeassistant.components.switch import DEVICE_CLASS_SWITCH, SwitchEntity
from homeassistant.components.switch import (
SwitchDeviceClass,
SwitchEntity,
)
from homeassistant.const import STATE_ON, STATE_OFF
from .const import (
DATA_JABLOTRON,
Expand All @@ -17,7 +20,7 @@ async def async_setup_entry(hass: core.HomeAssistant, config_entry: config_entri
class JablotronProgrammableOutputEntity(JablotronEntity, SwitchEntity):

_control: JablotronProgrammableOutput
_attr_device_class = DEVICE_CLASS_SWITCH
_attr_device_class = SwitchDeviceClass.SWITCH

def __init__(
self,
Expand Down

0 comments on commit 7e42c28

Please sign in to comment.