Skip to content

Commit

Permalink
Fix missing device_class from 2021.12.1 on (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
weltenwort authored Dec 16, 2021
1 parent 7450fb7 commit 861affc
Show file tree
Hide file tree
Showing 6 changed files with 805 additions and 527 deletions.
17 changes: 7 additions & 10 deletions custom_components/rct_power/lib/device_class_helpers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
from homeassistant.const import (
DEVICE_CLASS_CURRENT,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_VOLTAGE,
ELECTRIC_CURRENT_AMPERE,
ELECTRIC_CURRENT_MILLIAMPERE,
ELECTRIC_POTENTIAL_MILLIVOLT,
Expand All @@ -18,27 +13,29 @@
TEMP_KELVIN,
)

from homeassistant.components.sensor import SensorDeviceClass


def guess_device_class_from_unit(unit: str):
if unit in [TEMP_CELSIUS, TEMP_FAHRENHEIT, TEMP_KELVIN]:
return DEVICE_CLASS_TEMPERATURE
return SensorDeviceClass.TEMPERATURE
elif unit in [
ELECTRIC_POTENTIAL_VOLT,
ELECTRIC_POTENTIAL_MILLIVOLT,
]:
return DEVICE_CLASS_VOLTAGE
return SensorDeviceClass.VOLTAGE
elif unit in [
ELECTRIC_CURRENT_AMPERE,
ELECTRIC_CURRENT_MILLIAMPERE,
]:
return DEVICE_CLASS_CURRENT
return SensorDeviceClass.CURRENT
elif unit in [
POWER_WATT,
POWER_KILO_WATT,
POWER_VOLT_AMPERE,
]:
return DEVICE_CLASS_POWER
return SensorDeviceClass.POWER
elif unit in [ENERGY_KILO_WATT_HOUR, ENERGY_WATT_HOUR]:
return DEVICE_CLASS_ENERGY
return SensorDeviceClass.ENERGY

return None
16 changes: 8 additions & 8 deletions custom_components/rct_power/lib/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ def unit_of_measurement(self):
def extra_state_attributes(self) -> Dict[str, Any]:
return {}

@property
def device_info(self):
return self.entity_description.get_device_info(self)


class RctPowerSensorEntity(SensorEntity, RctPowerEntity):
entity_description: "RctPowerSensorEntityDescription"

@property
def device_class(self):
"""Return the device class of the sensor."""
Expand All @@ -127,14 +135,6 @@ def device_class(self):

return None

@property
def device_info(self):
return self.entity_description.get_device_info(self)


class RctPowerSensorEntity(SensorEntity, RctPowerEntity):
entity_description: "RctPowerSensorEntityDescription"

@property
def native_value(self):
values = [
Expand Down
2 changes: 1 addition & 1 deletion custom_components/rct_power/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"dependencies": [],
"config_flow": true,
"codeowners": ["@weltenwort"],
"requirements": ["rctclient==0.0.3", "async_timeout==3.0.1"],
"requirements": ["rctclient==0.0.3"],
"version": "0.8.2"
}
Loading

0 comments on commit 861affc

Please sign in to comment.