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
2 changes: 1 addition & 1 deletion homeassistant/components/homekit_controller/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"documentation": "https://www.home-assistant.io/integrations/homekit_controller",
"iot_class": "local_push",
"loggers": ["aiohomekit", "commentjson"],
"requirements": ["aiohomekit==3.2.17"],
"requirements": ["aiohomekit==3.2.18"],
"zeroconf": ["_hap._tcp.local.", "_hap._udp.local."]
}
3 changes: 0 additions & 3 deletions homeassistant/components/nam/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
},
"sps30_caqi_level": {
"default": "mdi:air-filter"
},
"sps30_pm4": {
"default": "mdi:molecule"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/nam/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ class NAMSensorEntityDescription(SensorEntityDescription):
translation_key="sps30_pm4",
suggested_display_precision=0,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
device_class=SensorDeviceClass.PM4,
state_class=SensorStateClass.MEASUREMENT,
value=lambda sensors: sensors.sps30_p4,
),
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/roborock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ async def setup_device_v1(
RoborockMqttClientV1, user_data, DeviceData(device, product_info.model)
)
try:
await mqtt_client.async_connect()
networking = await mqtt_client.get_networking()
if networking is None:
# If the api does not return an error but does return None for
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/roborock/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ async def _verify_api(self) -> None:
"""Verify that the api is reachable. If it is not, switch clients."""
if isinstance(self.api, RoborockLocalClientV1):
try:
await self.api.async_connect()
await self.api.ping()
except RoborockException:
_LOGGER.warning(
Expand Down
6 changes: 6 additions & 0 deletions homeassistant/components/shelly/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ def async_setup_rpc_attribute_entities(

for key in key_instances:
# Filter non-existing sensors
if description.role and description.role != coordinator.device.config[
key
].get("role"):
continue

if description.sub_key not in coordinator.device.status[
key
] and not description.supported(coordinator.device.status[key]):
Expand Down Expand Up @@ -310,6 +315,7 @@ class RpcEntityDescription(EntityDescription):
unit: Callable[[dict], str | None] | None = None
options_fn: Callable[[dict], list[str]] | None = None
entity_class: Callable | None = None
role: str | None = None


@dataclass(frozen=True)
Expand Down
79 changes: 79 additions & 0 deletions homeassistant/components/shelly/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
UnitOfFrequency,
UnitOfPower,
UnitOfTemperature,
UnitOfVolume,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
Expand Down Expand Up @@ -1458,6 +1459,84 @@ def __init__(
state_class=SensorStateClass.MEASUREMENT,
entity_class=RpcPresenceSensor,
),
"object_water_consumption": RpcSensorDescription(
key="object",
sub_key="value",
value=lambda status, _: float(status["counter"]["total"]),
native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
suggested_display_precision=3,
device_class=SensorDeviceClass.WATER,
state_class=SensorStateClass.TOTAL_INCREASING,
role="water_consumption",
),
"object_energy_consumption": RpcSensorDescription(
key="object",
sub_key="value",
value=lambda status, _: float(status["counter"]["total"]),
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
role="phase_info",
),
"object_total_act_energy": RpcSensorDescription(
key="object",
sub_key="value",
name="Total Active Energy",
value=lambda status, _: float(status["total_act_energy"]),
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
role="phase_info",
),
"object_total_power": RpcSensorDescription(
key="object",
sub_key="value",
name="Total Power",
value=lambda status, _: float(status["total_power"]),
native_unit_of_measurement=UnitOfPower.WATT,
suggested_unit_of_measurement=UnitOfPower.KILO_WATT,
suggested_display_precision=2,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
role="phase_info",
),
"object_phase_a_voltage": RpcSensorDescription(
key="object",
sub_key="value",
name="Phase A voltage",
value=lambda status, _: float(status["phase_a"]["voltage"]),
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
suggested_display_precision=1,
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
role="phase_info",
),
"object_phase_b_voltage": RpcSensorDescription(
key="object",
sub_key="value",
name="Phase B voltage",
value=lambda status, _: float(status["phase_b"]["voltage"]),
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
suggested_display_precision=1,
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
role="phase_info",
),
"object_phase_c_voltage": RpcSensorDescription(
key="object",
sub_key="value",
name="Phase C voltage",
value=lambda status, _: float(status["phase_c"]["voltage"]),
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
suggested_display_precision=1,
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
role="phase_info",
),
}


Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion requirements_test_all.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/components/nam/snapshots/test_sensor.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,7 @@
'suggested_display_precision': 0,
}),
}),
'original_device_class': None,
'original_device_class': <SensorDeviceClass.PM4: 'pm4'>,
'original_icon': None,
'original_name': 'SPS30 PM4',
'platform': 'nam',
Expand All @@ -1827,6 +1827,7 @@
# name: test_sensor[sensor.nettigo_air_monitor_sps30_pm4-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'pm4',
'friendly_name': 'Nettigo Air Monitor SPS30 PM4',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'μg/m³',
Expand Down
3 changes: 3 additions & 0 deletions tests/components/roborock/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ def bypass_api_fixture(bypass_api_client_fixture: Any, mock_send_message: Mock)
patch(
"homeassistant.components.roborock.coordinator.RoborockMqttClientV1._send_command"
),
patch(
"homeassistant.components.roborock.coordinator.RoborockLocalClientV1.async_connect"
),
patch(
"homeassistant.components.roborock.RoborockMqttClientV1.get_networking",
return_value=NETWORK_INFO,
Expand Down
28 changes: 28 additions & 0 deletions tests/components/shelly/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
UnitOfFrequency,
UnitOfPower,
UnitOfTemperature,
UnitOfVolume,
)
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers.device_registry import DeviceRegistry
Expand Down Expand Up @@ -1539,6 +1540,33 @@ async def test_rpc_device_virtual_number_sensor_with_device_class(
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.HUMIDITY


async def test_rpc_object_role_sensor(
hass: HomeAssistant,
mock_rpc_device: Mock,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test object role based sensor."""
config = deepcopy(mock_rpc_device.config)
config["object:200"] = {
"name": "Water consumption",
"meta": {"ui": {"unit": "m3"}},
"role": "water_consumption",
}

monkeypatch.setattr(mock_rpc_device, "config", config)

status = deepcopy(mock_rpc_device.status)
status["object:200"] = {"value": {"counter": {"total": 5.4}}}
monkeypatch.setattr(mock_rpc_device, "status", status)

await init_integration(hass, 3)

assert (state := hass.states.get("sensor.test_name_water_consumption"))
assert state.state == "5.4"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfVolume.CUBIC_METERS
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.WATER


@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_rpc_switch_energy_sensors(
hass: HomeAssistant,
Expand Down
Loading