Skip to content

Commit ff17801

Browse files
authored
Alpha 07 (#95)
* Remove some deprecated constants. * Fixed startup issue.
1 parent 197dc96 commit ff17801

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

changelog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
0.9.0a7:
2+
remove deprecated constants
3+
fix upgrade issue
14
0.9.0a6:
25
add an import notice
36
added Czech translation, thanks @Tony763

custom_components/virtual/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from .cfg import BlendedCfg, UpgradeCfg
3030

3131

32-
__version__ = '0.9.0a6'
32+
__version__ = '0.9.0a7'
3333

3434
_LOGGER = logging.getLogger(__name__)
3535

@@ -54,7 +54,7 @@
5454
]
5555

5656

57-
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
57+
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
5858
"""Set up a virtual component.
5959
"""
6060

custom_components/virtual/fan.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
ATTR_PERCENTAGE,
1818
ATTR_PRESET_MODE,
1919
DOMAIN as PLATFORM_DOMAIN,
20-
SUPPORT_DIRECTION,
21-
SUPPORT_OSCILLATE,
22-
SUPPORT_SET_SPEED,
2320
FanEntity,
21+
FanEntityFeature,
2422
)
2523
from homeassistant.config_entries import ConfigEntry
2624
from homeassistant.helpers.config_validation import (PLATFORM_SCHEMA)
@@ -91,30 +89,30 @@ def __init__(self, config):
9189

9290
self._attr_supported_features = 0
9391
if self._attr_speed_count > 0:
94-
self._attr_supported_features |= SUPPORT_SET_SPEED
92+
self._attr_supported_features |= FanEntityFeature.SET_SPEED
9593
if config.get(CONF_OSCILLATE, False):
96-
self._attr_supported_features |= SUPPORT_OSCILLATE
94+
self._attr_supported_features |= FanEntityFeature.OSCILLATE
9795
if config.get(CONF_DIRECTION, False):
98-
self._attr_supported_features |= SUPPORT_DIRECTION
96+
self._attr_supported_features |= FanEntityFeature.DIRECTION
9997

10098
_LOGGER.info(f"VirtualFan: {self.name} created")
10199

102100
def _create_state(self, config):
103101
super()._create_state(config)
104102

105-
if self._attr_supported_features & SUPPORT_DIRECTION:
103+
if self._attr_supported_features & FanEntityFeature.DIRECTION:
106104
self._attr_current_direction = "forward"
107-
if self._attr_supported_features & SUPPORT_OSCILLATE:
105+
if self._attr_supported_features & FanEntityFeature.OSCILLATE:
108106
self._attr_oscillating = False
109107
self._attr_percentage = None
110108
self._attr_preset_mode = None
111109

112110
def _restore_state(self, state, config):
113111
super()._restore_state(state, config)
114112

115-
if self._attr_supported_features & SUPPORT_DIRECTION:
113+
if self._attr_supported_features & FanEntityFeature.DIRECTION:
116114
self._attr_current_direction = state.attributes.get(ATTR_DIRECTION)
117-
if self._attr_supported_features & SUPPORT_OSCILLATE:
115+
if self._attr_supported_features & FanEntityFeature.OSCILLATE:
118116
self._attr_oscillating = state.attributes.get(ATTR_OSCILLATING)
119117
self._attr_percentage = state.attributes.get(ATTR_PERCENTAGE)
120118
self._attr_preset_mode = state.attributes.get(ATTR_PRESET_MODE)

custom_components/virtual/sensor.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@
2121
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
2222
CONCENTRATION_PARTS_PER_MILLION,
2323
CONF_UNIT_OF_MEASUREMENT,
24-
FREQUENCY_GIGAHERTZ,
24+
LIGHT_LUX,
2525
PERCENTAGE,
26-
POWER_VOLT_AMPERE,
2726
POWER_VOLT_AMPERE_REACTIVE,
28-
PRESSURE_HPA,
2927
SIGNAL_STRENGTH_DECIBELS,
30-
VOLUME_CUBIC_METERS,
28+
UnitOfApparentPower,
29+
UnitOfElectricCurrent,
30+
UnitOfElectricPotential,
31+
UnitOfEnergy,
32+
UnitOfFrequency,
33+
UnitOfPower,
34+
UnitOfPressure,
35+
UnitOfVolume,
3136
)
3237
from homeassistant.helpers.entity import Entity
3338
from homeassistant.helpers.typing import HomeAssistantType
@@ -59,12 +64,12 @@
5964
})
6065

6166
UNITS_OF_MEASUREMENT = {
62-
SensorDeviceClass.APPARENT_POWER: POWER_VOLT_AMPERE, # apparent power (VA)
67+
SensorDeviceClass.APPARENT_POWER: UnitOfApparentPower.VOLT_AMPERE, # apparent power (VA)
6368
SensorDeviceClass.BATTERY: PERCENTAGE, # % of battery that is left
6469
SensorDeviceClass.CO: CONCENTRATION_PARTS_PER_MILLION, # ppm of CO concentration
6570
SensorDeviceClass.CO2: CONCENTRATION_PARTS_PER_MILLION, # ppm of CO2 concentration
6671
SensorDeviceClass.HUMIDITY: PERCENTAGE, # % of humidity in the air
67-
SensorDeviceClass.ILLUMINANCE: "lm", # current light level (lx/lm)
72+
SensorDeviceClass.ILLUMINANCE: LIGHT_LUX, # current light level (lx/lm)
6873
SensorDeviceClass.NITROGEN_DIOXIDE: CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, # µg/m³ of nitrogen dioxide
6974
SensorDeviceClass.NITROGEN_MONOXIDE: CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, # µg/m³ of nitrogen monoxide
7075
SensorDeviceClass.NITROUS_OXIDE: CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, # µg/m³ of nitrogen oxide
@@ -75,16 +80,16 @@
7580
SensorDeviceClass.SIGNAL_STRENGTH: SIGNAL_STRENGTH_DECIBELS, # signal strength (dB/dBm)
7681
SensorDeviceClass.SULPHUR_DIOXIDE: CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, # µg/m³ of sulphur dioxide
7782
SensorDeviceClass.TEMPERATURE: "C", # temperature (C/F)
78-
SensorDeviceClass.PRESSURE: PRESSURE_HPA, # pressure (hPa/mbar)
79-
SensorDeviceClass.POWER: "kW", # power (W/kW)
80-
SensorDeviceClass.CURRENT: "A", # current (A)
81-
SensorDeviceClass.ENERGY: "kWh", # energy (Wh/kWh/MWh)
82-
SensorDeviceClass.FREQUENCY: FREQUENCY_GIGAHERTZ, # energy (Hz/kHz/MHz/GHz)
83+
SensorDeviceClass.PRESSURE: UnitOfPressure.HPA, # pressure (hPa/mbar)
84+
SensorDeviceClass.POWER: UnitOfPower.KILO_WATT, # power (W/kW)
85+
SensorDeviceClass.CURRENT: UnitOfElectricCurrent.AMPERE, # current (A)
86+
SensorDeviceClass.ENERGY: UnitOfEnergy.KILO_WATT_HOUR, # energy (Wh/kWh/MWh)
87+
SensorDeviceClass.FREQUENCY: UnitOfFrequency.GIGAHERTZ, # energy (Hz/kHz/MHz/GHz)
8388
SensorDeviceClass.POWER_FACTOR: PERCENTAGE, # power factor (no unit, min: -1.0, max: 1.0)
8489
SensorDeviceClass.REACTIVE_POWER: POWER_VOLT_AMPERE_REACTIVE, # reactive power (var)
8590
SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS: CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, # µg/m³ of vocs
86-
SensorDeviceClass.VOLTAGE: "V", # voltage (V)
87-
SensorDeviceClass.GAS: VOLUME_CUBIC_METERS, # gas (m³)
91+
SensorDeviceClass.VOLTAGE: UnitOfElectricPotential.VOLT, # voltage (V)
92+
SensorDeviceClass.GAS: UnitOfVolume.CUBIC_METERS, # gas (m³)
8893
}
8994

9095

0 commit comments

Comments
 (0)