Skip to content
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
25 changes: 24 additions & 1 deletion homeassistant/components/compit/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

PARALLEL_UPDATES = 0
NO_SENSOR = "no_sensor"
ON_STATES = ["on", "yes", "charging", "alert", "exceeded"]
ON_STATES = ["on", "yes", "charging", "alert", "exceeded", "open"]

DESCRIPTIONS: dict[CompitParameter, BinarySensorEntityDescription] = {
CompitParameter.AIRING: BinarySensorEntityDescription(
Expand Down Expand Up @@ -53,6 +53,18 @@
device_class=BinarySensorDeviceClass.PROBLEM,
entity_category=EntityCategory.DIAGNOSTIC,
),
CompitParameter.GWC: BinarySensorEntityDescription(
key=CompitParameter.GWC.value,
translation_key="ground_heat_exchanger_attached",
device_class=BinarySensorDeviceClass.CONNECTIVITY,
entity_category=EntityCategory.DIAGNOSTIC,
),
CompitParameter.MIXER_PUMP_STATUS: BinarySensorEntityDescription(
key=CompitParameter.MIXER_PUMP_STATUS.value,
translation_key="mixer_pump_status",
device_class=BinarySensorDeviceClass.RUNNING,
entity_category=EntityCategory.DIAGNOSTIC,
),
CompitParameter.PUMP_STATUS: BinarySensorEntityDescription(
key=CompitParameter.PUMP_STATUS.value,
translation_key="pump_status",
Expand All @@ -77,10 +89,20 @@ class CompitDeviceDescription:


DEVICE_DEFINITIONS: dict[int, CompitDeviceDescription] = {
3: CompitDeviceDescription(
name="R810",
parameters={
CompitParameter.MIXER_PUMP_STATUS: DESCRIPTIONS[
CompitParameter.MIXER_PUMP_STATUS
],
},
),
12: CompitDeviceDescription(
name="Nano Color",
parameters={
CompitParameter.AIRING: DESCRIPTIONS[CompitParameter.AIRING],
CompitParameter.CO2_LEVEL: DESCRIPTIONS[CompitParameter.CO2_LEVEL],
CompitParameter.GWC: DESCRIPTIONS[CompitParameter.GWC],
},
),
78: CompitDeviceDescription(
Expand All @@ -98,6 +120,7 @@ class CompitDeviceDescription:
parameters={
CompitParameter.AIRING: DESCRIPTIONS[CompitParameter.AIRING],
CompitParameter.CO2_LEVEL: DESCRIPTIONS[CompitParameter.CO2_LEVEL],
CompitParameter.GWC: DESCRIPTIONS[CompitParameter.GWC],
},
),
225: CompitDeviceDescription(
Expand Down
6 changes: 6 additions & 0 deletions homeassistant/components/compit/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
"dust_alert": {
"default": "mdi:alert"
},
"ground_heat_exchanger_attached": {
"default": "mdi:heat-pump"
},
"mixer_pump_status": {
"default": "mdi:pump"
},
"pump_status": {
"default": "mdi:pump"
},
Expand Down
6 changes: 6 additions & 0 deletions homeassistant/components/compit/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
"dust_alert": {
"name": "Dust alert"
},
"ground_heat_exchanger_attached": {
"name": "Ground heat exchanger attached"
},
"mixer_pump_status": {
"name": "Mixer pump"
},
"pump_status": {
"name": "Pump status"
},
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/eheimdigital/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"iot_class": "local_polling",
"loggers": ["eheimdigital"],
"quality_scale": "platinum",
"requirements": ["eheimdigital==1.7.0"],
"requirements": ["eheimdigital==1.7.1"],
"zeroconf": [
{ "name": "eheimdigital._http._tcp.local.", "type": "_http._tcp.local." }
]
Expand Down
22 changes: 22 additions & 0 deletions homeassistant/components/google_health/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from homeassistant.helpers.typing import StateType
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util import dt as dt_util
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM, UnitSystem

from . import GoogleHealthConfigEntry
from .const import DOMAIN
Expand All @@ -50,6 +51,7 @@ class GoogleHealthSensorEntityDescription[
"""Class describing Google Health sensor entities."""

value_fn: Callable[[Any], _ValueT]
suggested_unit_fn: Callable[[UnitSystem], str | None] | None = None


ACTIVITY_SENSORS: list[
Expand All @@ -69,6 +71,11 @@ class GoogleHealthSensorEntityDescription[
value_fn=lambda data: (
data.distance.millimeters_sum / 1000.0 if data and data.distance else 0.0
),
suggested_unit_fn=lambda units: (
UnitOfLength.MILES
if units is US_CUSTOMARY_SYSTEM
else UnitOfLength.KILOMETERS
),
),
GoogleHealthSensorEntityDescription[GoogleHealthActivityCoordinator, float](
key="active_calories",
Expand Down Expand Up @@ -109,6 +116,9 @@ class GoogleHealthSensorEntityDescription[
value_fn=lambda data: (
data.weight.weight_grams / 1000.0 if data and data.weight else None
),
suggested_unit_fn=lambda units: (
UnitOfMass.POUNDS if units is US_CUSTOMARY_SYSTEM else None
),
),
GoogleHealthSensorEntityDescription[GoogleHealthBodyCoordinator, int | None](
key="resting_heart_rate",
Expand Down Expand Up @@ -212,6 +222,9 @@ class GoogleHealthSensorEntityDescription[
if data and data.hydration and data.hydration.amount_consumed
else 0.0
),
suggested_unit_fn=lambda units: (
UnitOfVolume.FLUID_OUNCES if units is US_CUSTOMARY_SYSTEM else None
),
),
GoogleHealthSensorEntityDescription[GoogleHealthNutritionCoordinator, float](
key="calories_consumed",
Expand Down Expand Up @@ -345,6 +358,15 @@ def native_value(self) -> StateType:
"""Return the state of the sensor."""
return cast(StateType, self.entity_description.value_fn(self.coordinator.data))

@property
@override
def suggested_unit_of_measurement(self) -> str | None:
"""Return the suggested unit of measurement."""
if (suggested_unit_fn := self.entity_description.suggested_unit_fn) is not None:
return suggested_unit_fn(self.hass.config.units)

return super().suggested_unit_of_measurement


class GoogleHealthDeviceSensor(
CoordinatorEntity[GoogleHealthDeviceCoordinator], SensorEntity
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/media_player/intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,7 @@ async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse
)
or not (results := entity_response.result)
):
# No results found
return intent_obj.create_response()
raise intent.IntentHandleError(f"No results found for {search_query}")

# 2. Play Media (first result)
first_result = results[0]
Expand Down
61 changes: 52 additions & 9 deletions homeassistant/components/mikrotik/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,82 @@
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util import slugify

from .const import DOMAIN
from .coordinator import MikrotikDataUpdateCoordinator


class MikrotikEntity[DescriptionT: EntityDescription](
CoordinatorEntity[MikrotikDataUpdateCoordinator]
):
"""Base class for Mikrotik entities."""
class MikrotikBaseEntity(CoordinatorEntity[MikrotikDataUpdateCoordinator]):
"""Base class for all Mikrotik entities."""

_attr_has_entity_name = True
entity_description: DescriptionT

def __init__(
self,
coordinator: MikrotikDataUpdateCoordinator,
description: DescriptionT,
description: EntityDescription,
) -> None:
"""Initialize the entity."""
super().__init__(coordinator)
self.entity_description = description

self._serial = coordinator.api.serial_number
self._attr_device_info = DeviceInfo(

def _base_device_info(self) -> DeviceInfo:
"""Return the device info fields shared by all Mikrotik devices."""
coordinator = self.coordinator
return DeviceInfo(
configuration_url=URL.build(
scheme="http",
host=coordinator.host,
),
identifiers={(DOMAIN, self._serial)},
name=coordinator.hostname,
manufacturer="Mikrotik",
model=coordinator.model,
sw_version=coordinator.firmware,
serial_number=self._serial,
)


class MikrotikEntity(MikrotikBaseEntity):
"""Base class for Mikrotik entities."""

def __init__(
self,
coordinator: MikrotikDataUpdateCoordinator,
description: EntityDescription,
) -> None:
"""Initialize the entity."""
super().__init__(coordinator, description)
self._attr_device_info = DeviceInfo(
**self._base_device_info(),
identifiers={(DOMAIN, self._serial)},
name=coordinator.hostname,
)
self._attr_unique_id = f"{self._serial}_{description.key}"


class MikrotikDeviceEntity(MikrotikBaseEntity):
"""Base class for Mikrotik device entities."""

def __init__(
self,
coordinator: MikrotikDataUpdateCoordinator,
description: EntityDescription,
interface: dict,
) -> None:
"""Initialize the entity."""
super().__init__(coordinator, description)

name = interface.get("name")
ident = f"{slugify(interface.get('mac-address'))}_{name}"

self._attr_device_info = DeviceInfo(
**self._base_device_info(),
identifiers={(DOMAIN, ident)},
name=name,
via_device=(DOMAIN, coordinator.api.serial_number),
)
self._attr_unique_id = ident
self._attr_name = name
self._interface = interface
4 changes: 1 addition & 3 deletions homeassistant/components/mikrotik/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ async def async_setup_entry(
async_add_entities(sensors_list)


class MikrotikSensorEntity(
MikrotikEntity[MikrotikSensorEntityDescription], SensorEntity
):
class MikrotikSensorEntity(MikrotikEntity, SensorEntity):
"""Sensor device."""

entity_description: MikrotikSensorEntityDescription
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/mikrotik/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ async def async_setup_entry(
class MikrotikUpdateEntity(MikrotikEntity, UpdateEntity):
"""Mixin for update entity specific attributes."""

update_description: MikrotikUpdateEntityDescription
entity_description: MikrotikUpdateEntityDescription

@property
@override
def supported_features(self) -> UpdateEntityFeature:
"""Flag supported features."""
return cast(UpdateEntityFeature, self.entity_description.supported_features)
return self.entity_description.supported_features

@property
def _device_path_info(self) -> dict[str, Any]:
Expand Down
7 changes: 6 additions & 1 deletion homeassistant/components/shelly/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ def __init__(
ble_addr: str = coordinator.device.config[key]["addr"]
fw_ver = coordinator.device.status[key].get("fw_ver")
self._attr_device_info = get_blu_trv_device_info(
coordinator.device.config[key], ble_addr, coordinator.mac, fw_ver
coordinator.hass,
coordinator.config_entry.entry_id,
coordinator.device.config[key],
ble_addr,
coordinator.mac,
fw_ver,
)


Expand Down
7 changes: 6 additions & 1 deletion homeassistant/components/shelly/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,12 @@ def __init__(

self._attr_unique_id = f"{format_ble_addr(ble_addr)}-{key}-{attribute}"
self._attr_device_info = get_blu_trv_device_info(
config, ble_addr, coordinator.mac, fw_ver
coordinator.hass,
coordinator.config_entry.entry_id,
config,
ble_addr,
coordinator.mac,
fw_ver,
)

@rpc_call
Expand Down
7 changes: 6 additions & 1 deletion homeassistant/components/shelly/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,12 @@ def __init__(self, coordinator: ShellyRpcCoordinator, id_: int) -> None:
self._attr_unique_id = f"{ble_addr}-{self.key}"
fw_ver = coordinator.device.status[self.key].get("fw_ver")
self._attr_device_info = get_blu_trv_device_info(
self._config, ble_addr, self.coordinator.mac, fw_ver
coordinator.hass,
coordinator.config_entry.entry_id,
self._config,
ble_addr,
self.coordinator.mac,
fw_ver,
)

@property
Expand Down
4 changes: 4 additions & 0 deletions homeassistant/components/shelly/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,8 @@ def get_entity_block_device_info(
) -> DeviceInfo:
"""Get device info for block entities."""
return get_block_device_info(
coordinator.hass,
coordinator.config_entry.entry_id,
coordinator.device,
coordinator.mac,
coordinator.configuration_url,
Expand All @@ -746,6 +748,8 @@ def get_entity_rpc_device_info(
) -> DeviceInfo:
"""Get device info for RPC entities."""
return get_rpc_device_info(
coordinator.hass,
coordinator.config_entry.entry_id,
coordinator.device,
coordinator.mac,
coordinator.configuration_url,
Expand Down
7 changes: 6 additions & 1 deletion homeassistant/components/shelly/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ def __init__(
ble_addr: str = coordinator.device.config[key]["addr"]
fw_ver = coordinator.device.status[key].get("fw_ver")
self._attr_device_info = get_blu_trv_device_info(
coordinator.device.config[key], ble_addr, coordinator.mac, fw_ver
coordinator.hass,
coordinator.config_entry.entry_id,
coordinator.device.config[key],
ble_addr,
coordinator.mac,
fw_ver,
)


Expand Down
7 changes: 6 additions & 1 deletion homeassistant/components/shelly/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ def __init__(
ble_addr: str = coordinator.device.config[key]["addr"]
fw_ver = coordinator.device.status[key].get("fw_ver")
self._attr_device_info = get_blu_trv_device_info(
coordinator.device.config[key], ble_addr, coordinator.mac, fw_ver
coordinator.hass,
coordinator.config_entry.entry_id,
coordinator.device.config[key],
ble_addr,
coordinator.mac,
fw_ver,
)


Expand Down
Loading
Loading