Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error in HA 2024.1 (HA>=2023.1) #1246

Merged
merged 1 commit into from
Jan 5, 2024
Merged
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
13 changes: 5 additions & 8 deletions custom_components/xiaomi_gateway3/alarm_control_panel.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from homeassistant.components.alarm_control_panel import (
SUPPORT_ALARM_ARM_AWAY,
SUPPORT_ALARM_ARM_HOME,
SUPPORT_ALARM_ARM_NIGHT,
SUPPORT_ALARM_TRIGGER,
AlarmControlPanelEntityFeature,
AlarmControlPanelEntity,
)
from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -31,10 +28,10 @@ def new_entity(gateway: XGateway, device: XDevice, conv: Converter) -> XEntity:
class XiaomiAlarm(XEntity, AlarmControlPanelEntity):
_attr_code_arm_required = False
_attr_supported_features = (
SUPPORT_ALARM_ARM_HOME
| SUPPORT_ALARM_ARM_AWAY
| SUPPORT_ALARM_ARM_NIGHT
| SUPPORT_ALARM_TRIGGER
AlarmControlPanelEntityFeature.ARM_HOME
| AlarmControlPanelEntityFeature.ARM_AWAY
| AlarmControlPanelEntityFeature.ARM_NIGHT
| AlarmControlPanelEntityFeature.TRIGGER
)

@callback
Expand Down
25 changes: 12 additions & 13 deletions custom_components/xiaomi_gateway3/climate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from homeassistant.components.climate import *
from homeassistant.components.climate.const import *
from homeassistant.const import TEMP_CELSIUS
from homeassistant.core import callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback

Expand All @@ -11,9 +10,9 @@
from .core.gateway import XGateway

ACTIONS = {
HVAC_MODE_OFF: CURRENT_HVAC_OFF,
HVAC_MODE_COOL: CURRENT_HVAC_COOL,
HVAC_MODE_HEAT: CURRENT_HVAC_HEAT,
HVACMode.OFF: HVACAction.OFF,
HVACMode.COOL: HVACAction.COOLING,
HVACMode.HEAT: HVACAction.HEATING,
}


Expand All @@ -35,10 +34,10 @@ class XiaomiClimate(XEntity, ClimateEntity):
_attr_fan_mode = None
_attr_fan_modes = [FAN_LOW, FAN_MEDIUM, FAN_HIGH, FAN_AUTO]
_attr_hvac_mode = None
_attr_hvac_modes = [HVAC_MODE_OFF, HVAC_MODE_COOL, HVAC_MODE_HEAT]
_attr_hvac_modes = [HVACMode.OFF, HVACMode.COOL, HVACMode.HEAT]
_attr_precision = PRECISION_WHOLE
_attr_supported_features = SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE
_attr_temperature_unit = TEMP_CELSIUS
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE_RANGE | ClimateEntityFeature.FAN_MODE
_attr_temperature_unit = UnitOfTemperature.CELSIUS
# support only KTWKQ03ES for now
_attr_max_temp = 30
_attr_min_temp = 17
Expand Down Expand Up @@ -77,9 +76,9 @@ async def async_set_hvac_mode(self, hvac_mode: str) -> None:
# noinspection PyAbstractClass
class AqaraE1(XEntity, ClimateEntity):
_attr_hvac_mode = None
_attr_hvac_modes = [HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_AUTO]
_attr_supported_features = SUPPORT_TARGET_TEMPERATURE
_attr_temperature_unit = TEMP_CELSIUS
_attr_hvac_modes = [HVACMode.OFF, HVACMode.HEAT, HVACMode.AUTO]
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
_attr_temperature_unit = UnitOfTemperature.CELSIUS
_attr_max_temp = 30
_attr_min_temp = 5
_attr_target_temperature_step = 0.5
Expand All @@ -101,7 +100,7 @@ def async_set_state(self, data: dict):
if self._enabled is None or self._mode is None:
return

self._attr_hvac_mode = self._mode if self._enabled else HVAC_MODE_OFF
self._attr_hvac_mode = self._mode if self._enabled else HVACMode.OFF

async def async_update(self):
await self.device_read(self.subscribed_attrs)
Expand All @@ -110,9 +109,9 @@ async def async_set_temperature(self, **kwargs) -> None:
await self.device_send({"target_temp": kwargs[ATTR_TEMPERATURE]})

async def async_set_hvac_mode(self, hvac_mode: str) -> None:
if hvac_mode in (HVAC_MODE_HEAT, HVAC_MODE_AUTO):
if hvac_mode in (HVACMode.HEAT, HVACMode.AUTO):
payload = {"mode": hvac_mode}
elif hvac_mode == HVAC_MODE_OFF:
elif hvac_mode == HVACMode.OFF:
payload = {"climate": False}
else:
return
Expand Down
6 changes: 3 additions & 3 deletions custom_components/xiaomi_gateway3/number.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from homeassistant.components.number import NumberEntity
from homeassistant.components.number.const import DEFAULT_STEP
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import LENGTH_METERS, TIME_SECONDS
from homeassistant.const import UnitOfLength, UnitOfTime
from homeassistant.core import callback, HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

Expand All @@ -23,8 +23,8 @@ def new_entity(gateway: XGateway, device: XDevice, conv: Converter) -> XEntity:


UNITS = {
"approach_distance": LENGTH_METERS,
"occupancy_timeout": TIME_SECONDS,
"approach_distance": UnitOfLength.METERS,
"occupancy_timeout": UnitOfTime.SECONDS,
}


Expand Down
37 changes: 13 additions & 24 deletions custom_components/xiaomi_gateway3/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,18 @@ def new_entity(gateway: XGateway, device: XDevice, conv: Converter) -> XEntity:
"humidity": PERCENTAGE,
# zb light and motion and ble flower - lux
"illuminance": LIGHT_LUX,
# Deprecated: please use UnitOfPower.WATT.
"power": POWER_WATT,
# Deprecated: please use UnitOfElectricPotential.VOLT.
"voltage": ELECTRIC_POTENTIAL_VOLT,
# Deprecated: please use UnitOfElectricCurrent.AMPERE.
"current": ELECTRIC_CURRENT_AMPERE,
# Deprecated: please use UnitOfPressure.HPA
"pressure": PRESSURE_HPA,
# Deprecated: please use UnitOfTemperature.CELSIUS
"temperature": TEMP_CELSIUS,
# Deprecated: please use UnitOfEnergy.KILO_WATT_HOUR.
"energy": ENERGY_KILO_WATT_HOUR,
# Deprecated: please use UnitOfTemperature.CELSIUS
"chip_temperature": TEMP_CELSIUS,
"power": UnitOfPower.WATT,
"voltage": UnitOfElectricPotential.VOLT,
"current": UnitOfElectricCurrent.AMPERE,
"pressure": UnitOfPressure.HPA,
"temperature": UnitOfTemperature.CELSIUS,
"energy": UnitOfEnergy.KILO_WATT_HOUR,
"chip_temperature": UnitOfTemperature.CELSIUS,
"conductivity": CONDUCTIVITY,
"gas_density": "% LEL",
# Deprecated: please use UnitOfTime.SECONDS.
"idle_time": TIME_SECONDS,
"idle_time": UnitOfTime.SECONDS,
"linkquality": "lqi",
# Deprecated: please use UnitOfPower.WATT.
"max_power": POWER_WATT,
"max_power": UnitOfPower.WATT,
"moisture": PERCENTAGE,
"msg_received": "msg",
"msg_missed": "msg",
Expand All @@ -68,19 +59,17 @@ def new_entity(gateway: XGateway, device: XDevice, conv: Converter) -> XEntity:
"smoke_density": "% obs/ft",
"supply": PERCENTAGE,
"tvoc": CONCENTRATION_PARTS_PER_BILLION,
# Deprecated: please use UnitOfLength.METERS.
"distance": LENGTH_METERS,
"occupancy_duration": TIME_SECONDS,
"occupancy_distance": LENGTH_METERS,
"distance": UnitOfLength.METERS,
"occupancy_duration": UnitOfTime.SECONDS,
"occupancy_distance": UnitOfLength.METERS,
"formaldehyde": CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER,
# "link_quality": "lqi",
# "rssi": "dBm",
# "msg_received": "msg",
# "msg_missed": "msg",
# "unresponsive": "times"
"power_replenishment": "mAh",
# Deprecated: please use UnitOfElectricCurrent.MILLIAMPERE.
"realtime_current_in": ELECTRIC_CURRENT_MILLIAMPERE,
"realtime_current_in": UnitOfElectricCurrent.MILLIAMPERE,
}

# https://developers.home-assistant.io/docs/core/entity/sensor/#long-term-statistics
Expand Down
Loading