mirror of https://github.com/home-assistant/core
Use entity class attributes for Bsblan (#53165)
This commit is contained in:
parent
db1a8e9336
commit
a1df3519db
|
@ -132,9 +132,7 @@ omit =
|
||||||
homeassistant/components/brottsplatskartan/sensor.py
|
homeassistant/components/brottsplatskartan/sensor.py
|
||||||
homeassistant/components/browser/*
|
homeassistant/components/browser/*
|
||||||
homeassistant/components/brunt/cover.py
|
homeassistant/components/brunt/cover.py
|
||||||
homeassistant/components/bsblan/__init__.py
|
|
||||||
homeassistant/components/bsblan/climate.py
|
homeassistant/components/bsblan/climate.py
|
||||||
homeassistant/components/bsblan/const.py
|
|
||||||
homeassistant/components/bt_home_hub_5/device_tracker.py
|
homeassistant/components/bt_home_hub_5/device_tracker.py
|
||||||
homeassistant/components/bt_smarthub/device_tracker.py
|
homeassistant/components/bt_smarthub/device_tracker.py
|
||||||
homeassistant/components/buienradar/sensor.py
|
homeassistant/components/buienradar/sensor.py
|
||||||
|
|
|
@ -27,7 +27,6 @@ from homeassistant.const import (
|
||||||
TEMP_FAHRENHEIT,
|
TEMP_FAHRENHEIT,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
|
@ -88,6 +87,10 @@ async def async_setup_entry(
|
||||||
class BSBLanClimate(ClimateEntity):
|
class BSBLanClimate(ClimateEntity):
|
||||||
"""Defines a BSBLan climate device."""
|
"""Defines a BSBLan climate device."""
|
||||||
|
|
||||||
|
_attr_supported_features = SUPPORT_FLAGS
|
||||||
|
_attr_hvac_modes = HVAC_MODES
|
||||||
|
_attr_preset_modes = PRESET_MODES
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
entry_id: str,
|
entry_id: str,
|
||||||
|
@ -95,89 +98,33 @@ class BSBLanClimate(ClimateEntity):
|
||||||
info: Info,
|
info: Info,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize BSBLan climate device."""
|
"""Initialize BSBLan climate device."""
|
||||||
self._current_temperature: float | None = None
|
self._attr_available = True
|
||||||
self._available = True
|
|
||||||
self._hvac_mode: str | None = None
|
|
||||||
self._target_temperature: float | None = None
|
|
||||||
self._temperature_unit = None
|
|
||||||
self._preset_mode: str | None = None
|
|
||||||
self._store_hvac_mode = None
|
self._store_hvac_mode = None
|
||||||
self._info: Info = info
|
|
||||||
self.bsblan = bsblan
|
self.bsblan = bsblan
|
||||||
|
self._attr_name = self._attr_unique_id = info.device_identification
|
||||||
@property
|
self._attr_device_info = {
|
||||||
def name(self) -> str:
|
ATTR_IDENTIFIERS: {(DOMAIN, info.device_identification)},
|
||||||
"""Return the name of the entity."""
|
ATTR_NAME: "BSBLan Device",
|
||||||
return self._info.device_identification
|
ATTR_MANUFACTURER: "BSBLan",
|
||||||
|
ATTR_MODEL: info.controller_variant,
|
||||||
@property
|
}
|
||||||
def available(self) -> bool:
|
|
||||||
"""Return True if entity is available."""
|
|
||||||
return self._available
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self) -> str:
|
|
||||||
"""Return the unique ID for this sensor."""
|
|
||||||
return self._info.device_identification
|
|
||||||
|
|
||||||
@property
|
|
||||||
def temperature_unit(self) -> str:
|
|
||||||
"""Return the unit of measurement which this thermostat uses."""
|
|
||||||
if self._temperature_unit == "°C":
|
|
||||||
return TEMP_CELSIUS
|
|
||||||
return TEMP_FAHRENHEIT
|
|
||||||
|
|
||||||
@property
|
|
||||||
def supported_features(self) -> int:
|
|
||||||
"""Flag supported features."""
|
|
||||||
return SUPPORT_FLAGS
|
|
||||||
|
|
||||||
@property
|
|
||||||
def current_temperature(self):
|
|
||||||
"""Return the current temperature."""
|
|
||||||
return self._current_temperature
|
|
||||||
|
|
||||||
@property
|
|
||||||
def hvac_mode(self):
|
|
||||||
"""Return the current operation mode."""
|
|
||||||
return self._hvac_mode
|
|
||||||
|
|
||||||
@property
|
|
||||||
def hvac_modes(self):
|
|
||||||
"""Return the list of available operation modes."""
|
|
||||||
return HVAC_MODES
|
|
||||||
|
|
||||||
@property
|
|
||||||
def target_temperature(self):
|
|
||||||
"""Return the temperature we try to reach."""
|
|
||||||
return self._target_temperature
|
|
||||||
|
|
||||||
@property
|
|
||||||
def preset_modes(self):
|
|
||||||
"""List of available preset modes."""
|
|
||||||
return PRESET_MODES
|
|
||||||
|
|
||||||
@property
|
|
||||||
def preset_mode(self):
|
|
||||||
"""Return the preset_mode."""
|
|
||||||
return self._preset_mode
|
|
||||||
|
|
||||||
async def async_set_preset_mode(self, preset_mode):
|
async def async_set_preset_mode(self, preset_mode):
|
||||||
"""Set preset mode."""
|
"""Set preset mode."""
|
||||||
_LOGGER.debug("Setting preset mode to: %s", preset_mode)
|
_LOGGER.debug("Setting preset mode to: %s", preset_mode)
|
||||||
if preset_mode == PRESET_NONE:
|
if preset_mode == PRESET_NONE:
|
||||||
# restore previous hvac mode
|
# restore previous hvac mode
|
||||||
self._hvac_mode = self._store_hvac_mode
|
self._attr_hvac_mode = self._store_hvac_mode
|
||||||
else:
|
else:
|
||||||
# Store hvac mode.
|
# Store hvac mode.
|
||||||
self._store_hvac_mode = self._hvac_mode
|
self._store_hvac_mode = self._attr_hvac_mode
|
||||||
await self.async_set_data(preset_mode=preset_mode)
|
await self.async_set_data(preset_mode=preset_mode)
|
||||||
|
|
||||||
async def async_set_hvac_mode(self, hvac_mode):
|
async def async_set_hvac_mode(self, hvac_mode):
|
||||||
"""Set HVAC mode."""
|
"""Set HVAC mode."""
|
||||||
_LOGGER.debug("Setting HVAC mode to: %s", hvac_mode)
|
_LOGGER.debug("Setting HVAC mode to: %s", hvac_mode)
|
||||||
# preset should be none when hvac mode is set
|
# preset should be none when hvac mode is set
|
||||||
self._preset_mode = PRESET_NONE
|
self._attr_preset_mode = PRESET_NONE
|
||||||
await self.async_set_data(hvac_mode=hvac_mode)
|
await self.async_set_data(hvac_mode=hvac_mode)
|
||||||
|
|
||||||
async def async_set_temperature(self, **kwargs):
|
async def async_set_temperature(self, **kwargs):
|
||||||
|
@ -204,39 +151,33 @@ class BSBLanClimate(ClimateEntity):
|
||||||
await self.bsblan.thermostat(**data)
|
await self.bsblan.thermostat(**data)
|
||||||
except BSBLanError:
|
except BSBLanError:
|
||||||
_LOGGER.error("An error occurred while updating the BSBLan device")
|
_LOGGER.error("An error occurred while updating the BSBLan device")
|
||||||
self._available = False
|
self._attr_available = False
|
||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Update BSBlan entity."""
|
"""Update BSBlan entity."""
|
||||||
try:
|
try:
|
||||||
state: State = await self.bsblan.state()
|
state: State = await self.bsblan.state()
|
||||||
except BSBLanError:
|
except BSBLanError:
|
||||||
if self._available:
|
if self.available:
|
||||||
_LOGGER.error("An error occurred while updating the BSBLan device")
|
_LOGGER.error("An error occurred while updating the BSBLan device")
|
||||||
self._available = False
|
self._attr_available = False
|
||||||
return
|
return
|
||||||
|
|
||||||
self._available = True
|
self._attr_available = True
|
||||||
|
|
||||||
self._current_temperature = float(state.current_temperature.value)
|
self._attr_current_temperature = float(state.current_temperature.value)
|
||||||
self._target_temperature = float(state.target_temperature.value)
|
self._attr_target_temperature = float(state.target_temperature.value)
|
||||||
|
|
||||||
# check if preset is active else get hvac mode
|
# check if preset is active else get hvac mode
|
||||||
_LOGGER.debug("state hvac/preset mode: %s", state.hvac_mode.value)
|
_LOGGER.debug("state hvac/preset mode: %s", state.hvac_mode.value)
|
||||||
if state.hvac_mode.value == "2":
|
if state.hvac_mode.value == "2":
|
||||||
self._preset_mode = PRESET_ECO
|
self._attr_preset_mode = PRESET_ECO
|
||||||
else:
|
else:
|
||||||
self._hvac_mode = BSBLAN_TO_HA_STATE[state.hvac_mode.value]
|
self._attr_hvac_mode = BSBLAN_TO_HA_STATE[state.hvac_mode.value]
|
||||||
self._preset_mode = PRESET_NONE
|
self._attr_preset_mode = PRESET_NONE
|
||||||
|
|
||||||
self._temperature_unit = state.current_temperature.unit
|
self._attr_temperature_unit = (
|
||||||
|
TEMP_CELSIUS
|
||||||
@property
|
if state.current_temperature.unit == "°C"
|
||||||
def device_info(self) -> DeviceInfo:
|
else TEMP_FAHRENHEIT
|
||||||
"""Return device information about this BSBLan device."""
|
)
|
||||||
return {
|
|
||||||
ATTR_IDENTIFIERS: {(DOMAIN, self._info.device_identification)},
|
|
||||||
ATTR_NAME: "BSBLan Device",
|
|
||||||
ATTR_MANUFACTURER: "BSBLan",
|
|
||||||
ATTR_MODEL: self._info.controller_variant,
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue