Skip to content

Commit

Permalink
Alpha 07 (#95)
Browse files Browse the repository at this point in the history
* Remove some deprecated constants.

* Fixed startup issue.
  • Loading branch information
twrecked authored Feb 3, 2024
1 parent 197dc96 commit ff17801
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
3 changes: 3 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
0.9.0a7:
remove deprecated constants
fix upgrade issue
0.9.0a6:
add an import notice
added Czech translation, thanks @Tony763
Expand Down
4 changes: 2 additions & 2 deletions custom_components/virtual/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from .cfg import BlendedCfg, UpgradeCfg


__version__ = '0.9.0a6'
__version__ = '0.9.0a7'

_LOGGER = logging.getLogger(__name__)

Expand All @@ -54,7 +54,7 @@
]


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

Expand Down
18 changes: 8 additions & 10 deletions custom_components/virtual/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
ATTR_PERCENTAGE,
ATTR_PRESET_MODE,
DOMAIN as PLATFORM_DOMAIN,
SUPPORT_DIRECTION,
SUPPORT_OSCILLATE,
SUPPORT_SET_SPEED,
FanEntity,
FanEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.config_validation import (PLATFORM_SCHEMA)
Expand Down Expand Up @@ -91,30 +89,30 @@ def __init__(self, config):

self._attr_supported_features = 0
if self._attr_speed_count > 0:
self._attr_supported_features |= SUPPORT_SET_SPEED
self._attr_supported_features |= FanEntityFeature.SET_SPEED
if config.get(CONF_OSCILLATE, False):
self._attr_supported_features |= SUPPORT_OSCILLATE
self._attr_supported_features |= FanEntityFeature.OSCILLATE
if config.get(CONF_DIRECTION, False):
self._attr_supported_features |= SUPPORT_DIRECTION
self._attr_supported_features |= FanEntityFeature.DIRECTION

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

def _create_state(self, config):
super()._create_state(config)

if self._attr_supported_features & SUPPORT_DIRECTION:
if self._attr_supported_features & FanEntityFeature.DIRECTION:
self._attr_current_direction = "forward"
if self._attr_supported_features & SUPPORT_OSCILLATE:
if self._attr_supported_features & FanEntityFeature.OSCILLATE:
self._attr_oscillating = False
self._attr_percentage = None
self._attr_preset_mode = None

def _restore_state(self, state, config):
super()._restore_state(state, config)

if self._attr_supported_features & SUPPORT_DIRECTION:
if self._attr_supported_features & FanEntityFeature.DIRECTION:
self._attr_current_direction = state.attributes.get(ATTR_DIRECTION)
if self._attr_supported_features & SUPPORT_OSCILLATE:
if self._attr_supported_features & FanEntityFeature.OSCILLATE:
self._attr_oscillating = state.attributes.get(ATTR_OSCILLATING)
self._attr_percentage = state.attributes.get(ATTR_PERCENTAGE)
self._attr_preset_mode = state.attributes.get(ATTR_PRESET_MODE)
Expand Down
31 changes: 18 additions & 13 deletions custom_components/virtual/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
CONCENTRATION_PARTS_PER_MILLION,
CONF_UNIT_OF_MEASUREMENT,
FREQUENCY_GIGAHERTZ,
LIGHT_LUX,
PERCENTAGE,
POWER_VOLT_AMPERE,
POWER_VOLT_AMPERE_REACTIVE,
PRESSURE_HPA,
SIGNAL_STRENGTH_DECIBELS,
VOLUME_CUBIC_METERS,
UnitOfApparentPower,
UnitOfElectricCurrent,
UnitOfElectricPotential,
UnitOfEnergy,
UnitOfFrequency,
UnitOfPower,
UnitOfPressure,
UnitOfVolume,
)
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.typing import HomeAssistantType
Expand Down Expand Up @@ -59,12 +64,12 @@
})

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


Expand Down

0 comments on commit ff17801

Please sign in to comment.