class VolumeEntity(DeebotEntity, NumberEntity): # type: ignore """Volume number entity.""" entity_description = NumberEntityDescription( key="volume", entity_registry_enabled_default=False, entity_category=EntityCategory.CONFIG, ) _attr_min_value = 0 _attr_max_value = 10 _attr_step = 1.0 _attr_value = None async def async_added_to_hass(self) -> None: """Set up the event listeners now that hass is ready.""" await super().async_added_to_hass() async def on_volume(event: VolumeEvent) -> None: if event.maximum is not None: self._attr_max_value = event.maximum self._attr_value = event.volume self.async_write_ha_state() listener: EventListener = self._vacuum_bot.events.subscribe( VolumeEvent, on_volume) self.async_on_remove(listener.unsubscribe) @property def icon(self) -> Optional[str]: """Return the icon to use in the frontend, if any.""" if self._attr_value is not None: arrays = array_split( # type: ignore range(self._attr_min_value + 1, self._attr_max_value + 1), 3) if self._attr_value == self._attr_min_value: return "mdi:volume-off" if self._attr_value in arrays[0]: return "mdi:volume-low" if self._attr_value in arrays[1]: return "mdi:volume-medium" if self._attr_value in arrays[2]: return "mdi:volume-high" return "mdi:volume-medium" async def async_set_value(self, value: float) -> None: """Set new value.""" await self._vacuum_bot.execute_command(SetVolume(int(value)))
class VolumeNormalizationTargetEntity(MassBaseEntity, NumberEntity): """Representation of a number entity to set the volume normalization target.""" entity_description = NumberEntityDescription( key="volume_normalization_target", icon="mdi:chart-bar", entity_category=EntityCategory.CONFIG, unit_of_measurement=TIME_SECONDS, name="Volume normalization target", max_value=0, min_value=-40, step=1, ) @property def value(self) -> bool: """Return current value.""" return self.queue.settings.volume_normalization_target async def async_set_value(self, value: float) -> None: """Set new value.""" self.queue.settings.volume_normalization_target = value
class CrossfadeDurationEntity(MassBaseEntity, NumberEntity): """Representation of a number entity to set the crossfade duration.""" entity_description = NumberEntityDescription( key="crossfade_duration", icon="mdi:camera-timer", entity_category=EntityCategory.CONFIG, unit_of_measurement=TIME_SECONDS, name="Crossfade duration", max_value=10, min_value=0, step=1, ) @property def value(self) -> bool: """Return current value.""" return self.queue.settings.crossfade_duration async def async_set_value(self, value: float) -> None: """Set new value.""" self.queue.settings.crossfade_duration = int(value)
from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import HomeAssistantTuyaData from .base import IntegerTypeData, TuyaEntity from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode, DPType # All descriptions can be found here. Mostly the Integer data types in the # default instructions set of each category end up being a number. # https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq NUMBERS: dict[str, tuple[NumberEntityDescription, ...]] = { # Smart Kettle # https://developer.tuya.com/en/docs/iot/fbh?id=K9gf484m21yq7 "bh": ( NumberEntityDescription( key=DPCode.TEMP_SET, name="Temperature", icon="mdi:thermometer", entity_category=EntityCategory.CONFIG, ), NumberEntityDescription( key=DPCode.TEMP_SET_F, name="Temperature", icon="mdi:thermometer", entity_category=EntityCategory.CONFIG, ), NumberEntityDescription( key=DPCode.TEMP_BOILING_C, name="Temperature After Boiling", icon="mdi:thermometer", entity_category=EntityCategory.CONFIG, ), NumberEntityDescription(
update_segments = partial( async_update_segments, coordinator, set(), async_add_entities, ) coordinator.async_add_listener(update_segments) update_segments() NUMBERS = [ NumberEntityDescription( key=ATTR_SPEED, name="Speed", icon="mdi:speedometer", entity_category=ENTITY_CATEGORY_CONFIG, step=1, min_value=0, max_value=255, ), NumberEntityDescription( key=ATTR_INTENSITY, name="Intensity", entity_category=ENTITY_CATEGORY_CONFIG, step=1, min_value=0, max_value=255, ), ]
) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType from . import KNOWN_DEVICES from .connection import HKDevice from .entity import CharacteristicEntity NUMBER_ENTITIES: dict[str, NumberEntityDescription] = { CharacteristicsTypes.VENDOR_VOCOLINC_HUMIDIFIER_SPRAY_LEVEL: NumberEntityDescription( key=CharacteristicsTypes.VENDOR_VOCOLINC_HUMIDIFIER_SPRAY_LEVEL, name="Spray Quantity", icon="mdi:water", entity_category=EntityCategory.CONFIG, ), CharacteristicsTypes.VENDOR_EVE_DEGREE_ELEVATION: NumberEntityDescription( key=CharacteristicsTypes.VENDOR_EVE_DEGREE_ELEVATION, name="Elevation", icon="mdi:elevation-rise", entity_category=EntityCategory.CONFIG, ), CharacteristicsTypes.VENDOR_AQARA_GATEWAY_VOLUME: NumberEntityDescription( key=CharacteristicsTypes.VENDOR_AQARA_GATEWAY_VOLUME, name="Volume", icon="mdi:volume-high", entity_category=EntityCategory.CONFIG,
characteristics that don't map to a Home Assistant feature. """ from __future__ import annotations from aiohomekit.model.characteristics import Characteristic, CharacteristicsTypes from homeassistant.components.number import NumberEntity, NumberEntityDescription from homeassistant.core import callback from . import KNOWN_DEVICES, CharacteristicEntity NUMBER_ENTITIES: dict[str, NumberEntityDescription] = { CharacteristicsTypes.Vendor.VOCOLINC_HUMIDIFIER_SPRAY_LEVEL: NumberEntityDescription( key=CharacteristicsTypes.Vendor.VOCOLINC_HUMIDIFIER_SPRAY_LEVEL, name="Spray Quantity", icon="mdi:water", ), CharacteristicsTypes.Vendor.EVE_DEGREE_ELEVATION: NumberEntityDescription( key=CharacteristicsTypes.Vendor.EVE_DEGREE_ELEVATION, name="Elevation", icon="mdi:elevation-rise", ), } async def async_setup_entry(hass, config_entry, async_add_entities): """Set up Homekit numbers.""" hkid = config_entry.data["AccessoryPairingID"] conn = hass.data[KNOWN_DEVICES][hkid]
from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import HomeAssistantTuyaData from .base import IntegerTypeData, TuyaEntity from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode # All descriptions can be found here. Mostly the Integer data types in the # default instructions set of each category end up being a number. # https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq NUMBERS: dict[str, tuple[NumberEntityDescription, ...]] = { # Smart Kettle # https://developer.tuya.com/en/docs/iot/fbh?id=K9gf484m21yq7 "bh": ( NumberEntityDescription( key=DPCode.TEMP_SET, name="Temperature", icon="mdi:thermometer", entity_category=ENTITY_CATEGORY_CONFIG, ), NumberEntityDescription( key=DPCode.TEMP_SET_F, name="Temperature", icon="mdi:thermometer", entity_category=ENTITY_CATEGORY_CONFIG, ), NumberEntityDescription( key=DPCode.TEMP_BOILING_C, name="Temperature After Boiling", icon="mdi:thermometer", entity_category=ENTITY_CATEGORY_CONFIG, ), NumberEntityDescription(
DEFAULT_STEP, ) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType from . import KNOWN_DEVICES, CharacteristicEntity from .connection import HKDevice NUMBER_ENTITIES: dict[str, NumberEntityDescription] = { CharacteristicsTypes.VENDOR_VOCOLINC_HUMIDIFIER_SPRAY_LEVEL: NumberEntityDescription( key=CharacteristicsTypes.VENDOR_VOCOLINC_HUMIDIFIER_SPRAY_LEVEL, name="Spray Quantity", icon="mdi:water", entity_category=EntityCategory.CONFIG, ), CharacteristicsTypes.VENDOR_EVE_DEGREE_ELEVATION: NumberEntityDescription( key=CharacteristicsTypes.VENDOR_EVE_DEGREE_ELEVATION, name="Elevation", icon="mdi:elevation-rise", entity_category=EntityCategory.CONFIG, ), CharacteristicsTypes.VENDOR_AQARA_GATEWAY_VOLUME: NumberEntityDescription( key=CharacteristicsTypes.VENDOR_AQARA_GATEWAY_VOLUME, name="Volume", icon="mdi:volume-high", entity_category=EntityCategory.CONFIG,
from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import HomeAssistantTuyaData from .base import IntegerTypeData, TuyaEntity from .const import DEVICE_CLASS_UNITS, DOMAIN, TUYA_DISCOVERY_NEW, DPCode, DPType # All descriptions can be found here. Mostly the Integer data types in the # default instructions set of each category end up being a number. # https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq NUMBERS: dict[str, tuple[NumberEntityDescription, ...]] = { # Multi-functional Sensor # https://developer.tuya.com/en/docs/iot/categorydgnbj?id=Kaiuz3yorvzg3 "dgnbj": ( NumberEntityDescription( key=DPCode.ALARM_TIME, name="Time", entity_category=EntityCategory.CONFIG, ), ), # Smart Kettle # https://developer.tuya.com/en/docs/iot/fbh?id=K9gf484m21yq7 "bh": ( NumberEntityDescription( key=DPCode.TEMP_SET, name="Temperature", device_class=NumberDeviceClass.TEMPERATURE, icon="mdi:thermometer", entity_category=EntityCategory.CONFIG, ), NumberEntityDescription( key=DPCode.TEMP_SET_F,
"""Fully Kiosk Browser number.""" from homeassistant.components.number import NumberEntity, NumberEntityDescription from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import DOMAIN ENTITY_TYPES: tuple[NumberEntityDescription, ...] = ( NumberEntityDescription( key="timeToScreensaverV2", name="Screensaver Timer", entity_category=EntityCategory.CONFIG, ), NumberEntityDescription( key="screensaverBrightness", name="Screensaver Brightness", entity_category=EntityCategory.CONFIG, ), NumberEntityDescription( key="timeToScreenOffV2", name="Screen Off Timer", entity_category=EntityCategory.CONFIG, ), ) async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Fully Kiosk Browser number entities.""" coordinator = hass.data[DOMAIN][config_entry.entry_id]
update_segments = partial( async_update_segments, coordinator, set(), async_add_entities, ) coordinator.async_add_listener(update_segments) update_segments() NUMBERS = [ NumberEntityDescription( key=ATTR_SPEED, name="Speed", icon="mdi:speedometer", entity_category=EntityCategory.CONFIG, native_step=1, native_min_value=0, native_max_value=255, ), NumberEntityDescription( key=ATTR_INTENSITY, name="Intensity", entity_category=EntityCategory.CONFIG, native_step=1, native_min_value=0, native_max_value=255, ), ]