Use new enums in notion (#61950)

This commit is contained in:
epenet 2021-12-15 21:46:48 +01:00 committed by GitHub
parent 77829e397b
commit 1e9e056671
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 24 deletions

View file

@ -5,19 +5,13 @@ from dataclasses import dataclass
from typing import Literal from typing import Literal
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
DEVICE_CLASS_BATTERY, BinarySensorDeviceClass,
DEVICE_CLASS_CONNECTIVITY,
DEVICE_CLASS_DOOR,
DEVICE_CLASS_GARAGE_DOOR,
DEVICE_CLASS_MOISTURE,
DEVICE_CLASS_SMOKE,
DEVICE_CLASS_WINDOW,
BinarySensorEntity, BinarySensorEntity,
BinarySensorEntityDescription, BinarySensorEntityDescription,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import NotionEntity from . import NotionEntity
@ -55,63 +49,63 @@ BINARY_SENSOR_DESCRIPTIONS = (
NotionBinarySensorDescription( NotionBinarySensorDescription(
key=SENSOR_BATTERY, key=SENSOR_BATTERY,
name="Low Battery", name="Low Battery",
device_class=DEVICE_CLASS_BATTERY, device_class=BinarySensorDeviceClass.BATTERY,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
on_state="critical", on_state="critical",
), ),
NotionBinarySensorDescription( NotionBinarySensorDescription(
key=SENSOR_DOOR, key=SENSOR_DOOR,
name="Door", name="Door",
device_class=DEVICE_CLASS_DOOR, device_class=BinarySensorDeviceClass.DOOR,
on_state="open", on_state="open",
), ),
NotionBinarySensorDescription( NotionBinarySensorDescription(
key=SENSOR_GARAGE_DOOR, key=SENSOR_GARAGE_DOOR,
name="Garage Door", name="Garage Door",
device_class=DEVICE_CLASS_GARAGE_DOOR, device_class=BinarySensorDeviceClass.GARAGE_DOOR,
on_state="open", on_state="open",
), ),
NotionBinarySensorDescription( NotionBinarySensorDescription(
key=SENSOR_LEAK, key=SENSOR_LEAK,
name="Leak Detector", name="Leak Detector",
device_class=DEVICE_CLASS_MOISTURE, device_class=BinarySensorDeviceClass.MOISTURE,
on_state="leak", on_state="leak",
), ),
NotionBinarySensorDescription( NotionBinarySensorDescription(
key=SENSOR_MISSING, key=SENSOR_MISSING,
name="Missing", name="Missing",
device_class=DEVICE_CLASS_CONNECTIVITY, device_class=BinarySensorDeviceClass.CONNECTIVITY,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
on_state="not_missing", on_state="not_missing",
), ),
NotionBinarySensorDescription( NotionBinarySensorDescription(
key=SENSOR_SAFE, key=SENSOR_SAFE,
name="Safe", name="Safe",
device_class=DEVICE_CLASS_DOOR, device_class=BinarySensorDeviceClass.DOOR,
on_state="open", on_state="open",
), ),
NotionBinarySensorDescription( NotionBinarySensorDescription(
key=SENSOR_SLIDING, key=SENSOR_SLIDING,
name="Sliding Door/Window", name="Sliding Door/Window",
device_class=DEVICE_CLASS_DOOR, device_class=BinarySensorDeviceClass.DOOR,
on_state="open", on_state="open",
), ),
NotionBinarySensorDescription( NotionBinarySensorDescription(
key=SENSOR_SMOKE_CO, key=SENSOR_SMOKE_CO,
name="Smoke/Carbon Monoxide Detector", name="Smoke/Carbon Monoxide Detector",
device_class=DEVICE_CLASS_SMOKE, device_class=BinarySensorDeviceClass.SMOKE,
on_state="alarm", on_state="alarm",
), ),
NotionBinarySensorDescription( NotionBinarySensorDescription(
key=SENSOR_WINDOW_HINGED_HORIZONTAL, key=SENSOR_WINDOW_HINGED_HORIZONTAL,
name="Hinged Window", name="Hinged Window",
device_class=DEVICE_CLASS_WINDOW, device_class=BinarySensorDeviceClass.WINDOW,
on_state="open", on_state="open",
), ),
NotionBinarySensorDescription( NotionBinarySensorDescription(
key=SENSOR_WINDOW_HINGED_VERTICAL, key=SENSOR_WINDOW_HINGED_VERTICAL,
name="Hinged Window", name="Hinged Window",
device_class=DEVICE_CLASS_WINDOW, device_class=BinarySensorDeviceClass.WINDOW,
on_state="open", on_state="open",
), ),
) )

View file

@ -1,11 +1,12 @@
"""Support for Notion sensors.""" """Support for Notion sensors."""
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT, SensorDeviceClass,
SensorEntity, SensorEntity,
SensorEntityDescription, SensorEntityDescription,
SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS from homeassistant.const import TEMP_CELSIUS
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -16,9 +17,9 @@ SENSOR_DESCRIPTIONS = (
SensorEntityDescription( SensorEntityDescription(
key=SENSOR_TEMPERATURE, key=SENSOR_TEMPERATURE,
name="Temperature", name="Temperature",
device_class=DEVICE_CLASS_TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=TEMP_CELSIUS,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
) )