Skip to content

Commit

Permalink
fix: usage of key in SensorEntityDescription
Browse files Browse the repository at this point in the history
  • Loading branch information
petrleocompel committed Jan 22, 2024
1 parent 3f37ef5 commit 61aa83c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 10 additions & 1 deletion custom_components/hikvision_axpro/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from typing import Final


DOMAIN: Final[str] = "hikvision_axpro"

DATA_COORDINATOR: Final[str] = "hikaxpro"
Expand All @@ -14,3 +13,13 @@
INTERNAL_API: Final[str] = "internal_api"

ENABLE_DEBUG_OUTPUT: Final[str] = "debug"


# Sensor entity description constants
ENTITY_DESC_KEY_BATTERY: Final[str] = "battery"
ENTITY_DESC_KEY_MAGNET_PRESENCE: Final[str] = "magnet_presence"
ENTITY_DESC_KEY_MAGNET_SHOCK: Final[str] = "magnet_shock"
ENTITY_DESC_KEY_MAGNET_TILT: Final[str] = "magnet_tilt"
ENTITY_DESC_KEY_SIGNAL_STRENGTH: Final[str] = "signal_strength"
ENTITY_DESC_KEY_HUMIDITY: Final[str] = "humidity"
ENTITY_DESC_KEY_TEMPERATURE: Final[str] = "temperature"
10 changes: 5 additions & 5 deletions custom_components/hikvision_axpro/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


from . import HikAxProDataUpdateCoordinator
from .const import DATA_COORDINATOR, DOMAIN
from .const import DATA_COORDINATOR, DOMAIN, ENTITY_DESC_KEY_BATTERY, ENTITY_DESC_KEY_HUMIDITY, ENTITY_DESC_KEY_SIGNAL_STRENGTH, ENTITY_DESC_KEY_TEMPERATURE
from .model import DetectorType, Zone, Status, detector_model_to_name

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -502,7 +502,7 @@ def __init__(
f"{SENSOR_DOMAIN}.{coordinator.device_name}-temperature-{zone.id}"
)
self.entity_description = SensorEntityDescription(
SensorDeviceClass.TEMPERATURE,
key=ENTITY_DESC_KEY_TEMPERATURE,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
Expand Down Expand Up @@ -546,7 +546,7 @@ def __init__(
self._attr_has_entity_name = True
self.entity_id = f"{SENSOR_DOMAIN}.{coordinator.device_name}-humidity-{zone.id}"
self.entity_description = SensorEntityDescription(
SensorDeviceClass.HUMIDITY,
key=ENTITY_DESC_KEY_HUMIDITY,
device_class=SensorDeviceClass.HUMIDITY,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE,
Expand Down Expand Up @@ -590,7 +590,7 @@ def __init__(
self._attr_has_entity_name = True
self.entity_id = f"{SENSOR_DOMAIN}.{coordinator.device_name}-battery-{zone.id}"
self.entity_description = SensorEntityDescription(
SensorDeviceClass.BATTERY,
key=ENTITY_DESC_KEY_BATTERY,
device_class=SensorDeviceClass.BATTERY,
entity_category=EntityCategory.DIAGNOSTIC,
state_class=SensorStateClass.MEASUREMENT,
Expand Down Expand Up @@ -635,7 +635,7 @@ def __init__(
self._attr_has_entity_name = True
self.entity_id = f"{SENSOR_DOMAIN}.{coordinator.device_name}-signal-{zone.id}"
self.entity_description = SensorEntityDescription(
SensorDeviceClass.SIGNAL_STRENGTH,
key=ENTITY_DESC_KEY_SIGNAL_STRENGTH,
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
entity_category=EntityCategory.DIAGNOSTIC,
state_class=SensorStateClass.MEASUREMENT,
Expand Down

0 comments on commit 61aa83c

Please sign in to comment.