Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions custom_components/sonoff/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
SensorStateClass,
)
from homeassistant.const import (
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
CONCENTRATION_PARTS_PER_MILLION,
PERCENTAGE,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
UnitOfElectricCurrent,
Expand All @@ -21,6 +19,17 @@
)
from homeassistant.util import dt

try:
from homeassistant.const import UnitOfDensity, UnitOfRatio
except ImportError:
from homeassistant.const import (
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER as MICROGRAMS_PER_CUBIC_METER,
CONCENTRATION_PARTS_PER_MILLION as PARTS_PER_MILLION,
)
else:
MICROGRAMS_PER_CUBIC_METER = UnitOfDensity.MICROGRAMS_PER_CUBIC_METER
PARTS_PER_MILLION = UnitOfRatio.PARTS_PER_MILLION

from .core.const import DOMAIN
from .core.entity import XEntity
from .core.ewelink import SIGNAL_ADD_ENTITIES, XRegistry
Expand Down Expand Up @@ -58,16 +67,16 @@ async def async_setup_entry(hass, config_entry, add_entities):
UNITS = {
"battery": PERCENTAGE,
"battery_voltage": UnitOfElectricPotential.VOLT,
"co2": CONCENTRATION_PARTS_PER_MILLION,
"co2": PARTS_PER_MILLION,
"cpu_temperature": UnitOfTemperature.CELSIUS,
"current": UnitOfElectricCurrent.AMPERE,
"current_supply": UnitOfElectricCurrent.AMPERE,
"humidity": PERCENTAGE,
"outdoor_temp": UnitOfTemperature.CELSIUS,
"power": UnitOfPower.WATT,
"power_supply": UnitOfPower.WATT,
"pm25": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
"pm10": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
"pm25": MICROGRAMS_PER_CUBIC_METER,
"pm10": MICROGRAMS_PER_CUBIC_METER,
"remote_temperature": UnitOfTemperature.CELSIUS,
"rssi": SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
"temperature": UnitOfTemperature.CELSIUS,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from homeassistant.components.switch import SwitchEntity
from homeassistant.components.script import ATTR_LAST_TRIGGERED
from homeassistant.const import (
CONCENTRATION_PARTS_PER_MILLION,
MAJOR_VERSION,
MINOR_VERSION,
STATE_ON,
Expand Down Expand Up @@ -54,6 +53,7 @@
from custom_components.sonoff.number import XNumber, XPulseWidth
from custom_components.sonoff.select import XSelectStartup
from custom_components.sonoff.sensor import (
PARTS_PER_MILLION,
XButtonKey,
XButtonLocalKey,
XCloudEnergyDualR3,
Expand Down Expand Up @@ -2664,7 +2664,7 @@ def test_sawf_08p():
assert co2.name == "Device1 CO2"
assert co2.state == 510
assert co2.device_class == SensorDeviceClass.CO2
assert co2.native_unit_of_measurement == CONCENTRATION_PARTS_PER_MILLION
assert co2.native_unit_of_measurement == PARTS_PER_MILLION
assert co2.state_class == SensorStateClass.MEASUREMENT


Expand Down
Loading