Skip to content

Commit

Permalink
Use new device_class tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
theneweinstein committed Dec 12, 2021
1 parent 21f57cc commit b7175d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion custom_components/somneo/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "somneo",
"name": "Philips Somneo",
"version": "2.2.1",
"version": "2.2.2",
"documentation": "https://github.com/theneweinstein/somneo",
"issue_tracker": "https://github.com/theneweinstein/somneo/issues",
"dependencies": [],
Expand Down
15 changes: 7 additions & 8 deletions custom_components/somneo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

from datetime import datetime

from homeassistant.const import DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_PRESSURE, DEVICE_CLASS_TIMESTAMP
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
from homeassistant.components.sensor import SensorDeviceClass, STATE_CLASS_MEASUREMENT, SensorEntity

from .const import *

Expand Down Expand Up @@ -47,16 +46,16 @@ def __init__(self, name, data, device_info, serial, sensor_type):
self._attr_unique_id = serial + '_' + sensor_type

@property
def device_class(self):
def device_class(self) -> SensorDeviceClass:
"""Return the class of this device, from component DEVICE_CLASSES."""
if self._type == "temperature":
return DEVICE_CLASS_TEMPERATURE
return SensorDeviceClass.TEMPERATURE
if self._type == "humidity":
return DEVICE_CLASS_HUMIDITY
return SensorDeviceClass.HUMIDITY
if self._type == "luminance":
return DEVICE_CLASS_ILLUMINANCE
return SensorDeviceClass.ILLUMINANCE
if self._type == "pressure":
return DEVICE_CLASS_PRESSURE
return SensorDeviceClass.PRESSURE
else:
return None

Expand All @@ -82,7 +81,7 @@ def __init__(self, name, data, device_info, serial):
self._attr_device_info = device_info
self._attr_unique_id = serial + '_next_alarm'
self._attr_native_value = None
self._attr_device_class = DEVICE_CLASS_TIMESTAMP
self._attr_device_class = SensorDeviceClass.TIMESTAMP

async def async_update(self):
"""Get the latest data and updates the states."""
Expand Down

0 comments on commit b7175d3

Please sign in to comment.