mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 17:04:04 -04:00
Add supported device[Plug-Mini-EU] for switchbot cloud (#151019)
This commit is contained in:
@@ -143,6 +143,7 @@ async def make_device_data(
|
||||
"Relay Switch 1PM",
|
||||
"Plug Mini (US)",
|
||||
"Plug Mini (JP)",
|
||||
"Plug Mini (EU)",
|
||||
]:
|
||||
coordinator = await coordinator_for_device(
|
||||
hass, entry, api, device, coordinators_by_id
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
"""Platform for sensor integration."""
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from switchbot_api import Device, SwitchBotAPI
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
@@ -14,6 +18,7 @@ from homeassistant.const import (
|
||||
PERCENTAGE,
|
||||
UnitOfElectricCurrent,
|
||||
UnitOfElectricPotential,
|
||||
UnitOfEnergy,
|
||||
UnitOfPower,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
@@ -32,9 +37,26 @@ SENSOR_TYPE_CO2 = "CO2"
|
||||
SENSOR_TYPE_POWER = "power"
|
||||
SENSOR_TYPE_VOLTAGE = "voltage"
|
||||
SENSOR_TYPE_CURRENT = "electricCurrent"
|
||||
SENSOR_TYPE_USED_ELECTRICITY = "usedElectricity"
|
||||
SENSOR_TYPE_LIGHTLEVEL = "lightLevel"
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class SwitchbotCloudSensorEntityDescription(SensorEntityDescription):
|
||||
"""Plug Mini Eu UsedElectricity Sensor EntityDescription."""
|
||||
|
||||
value_fn: Callable[[Any], Any] = lambda value: value
|
||||
|
||||
|
||||
USED_ELECTRICITY_DESCRIPTION = SwitchbotCloudSensorEntityDescription(
|
||||
key=SENSOR_TYPE_USED_ELECTRICITY,
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||
suggested_display_precision=2,
|
||||
value_fn=lambda data: (data.get(SENSOR_TYPE_USED_ELECTRICITY) or 0) / 60000,
|
||||
)
|
||||
|
||||
TEMPERATURE_DESCRIPTION = SensorEntityDescription(
|
||||
key=SENSOR_TYPE_TEMPERATURE,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
@@ -129,6 +151,12 @@ SENSOR_DESCRIPTIONS_BY_DEVICE_TYPES = {
|
||||
VOLTAGE_DESCRIPTION,
|
||||
CURRENT_DESCRIPTION_IN_MA,
|
||||
),
|
||||
"Plug Mini (EU)": (
|
||||
POWER_DESCRIPTION,
|
||||
VOLTAGE_DESCRIPTION,
|
||||
CURRENT_DESCRIPTION_IN_MA,
|
||||
USED_ELECTRICITY_DESCRIPTION,
|
||||
),
|
||||
"Hub 2": (
|
||||
TEMPERATURE_DESCRIPTION,
|
||||
HUMIDITY_DESCRIPTION,
|
||||
@@ -198,4 +226,15 @@ class SwitchBotCloudSensor(SwitchBotCloudEntity, SensorEntity):
|
||||
"""Set attributes from coordinator data."""
|
||||
if not self.coordinator.data:
|
||||
return
|
||||
self._attr_native_value = self.coordinator.data.get(self.entity_description.key)
|
||||
|
||||
if isinstance(
|
||||
self.entity_description,
|
||||
SwitchbotCloudSensorEntityDescription,
|
||||
):
|
||||
self._attr_native_value = self.entity_description.value_fn(
|
||||
self.coordinator.data
|
||||
)
|
||||
else:
|
||||
self._attr_native_value = self.coordinator.data.get(
|
||||
self.entity_description.key
|
||||
)
|
||||
|
||||
@@ -83,13 +83,10 @@ def _async_make_entity(
|
||||
"""Make a SwitchBotCloudSwitch or SwitchBotCloudRemoteSwitch."""
|
||||
if isinstance(device, Remote):
|
||||
return SwitchBotCloudRemoteSwitch(api, device, coordinator)
|
||||
if device.device_type in ["Relay Switch 1PM", "Relay Switch 1", "Plug Mini (EU)"]:
|
||||
return SwitchBotCloudRelaySwitchSwitch(api, device, coordinator)
|
||||
if "Plug" in device.device_type:
|
||||
return SwitchBotCloudPlugSwitch(api, device, coordinator)
|
||||
if device.device_type in [
|
||||
"Relay Switch 1PM",
|
||||
"Relay Switch 1",
|
||||
]:
|
||||
return SwitchBotCloudRelaySwitchSwitch(api, device, coordinator)
|
||||
if "Bot" in device.device_type:
|
||||
return SwitchBotCloudSwitch(api, device, coordinator)
|
||||
raise NotImplementedError(f"Unsupported device type: {device.device_type}")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# serializer version: 1
|
||||
# name: test_meter[device_info0-0][sensor.meter_1_battery-entry]
|
||||
# name: test_no_coordinator_data[Meter][sensor.meter_1_battery-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
@@ -36,7 +36,7 @@
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info0-0][sensor.meter_1_battery-state]
|
||||
# name: test_no_coordinator_data[Meter][sensor.meter_1_battery-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'battery',
|
||||
@@ -52,7 +52,7 @@
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info0-0][sensor.meter_1_humidity-entry]
|
||||
# name: test_no_coordinator_data[Meter][sensor.meter_1_humidity-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
@@ -89,7 +89,7 @@
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info0-0][sensor.meter_1_humidity-state]
|
||||
# name: test_no_coordinator_data[Meter][sensor.meter_1_humidity-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'humidity',
|
||||
@@ -105,7 +105,7 @@
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info0-0][sensor.meter_1_temperature-entry]
|
||||
# name: test_no_coordinator_data[Meter][sensor.meter_1_temperature-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
@@ -145,7 +145,7 @@
|
||||
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info0-0][sensor.meter_1_temperature-state]
|
||||
# name: test_no_coordinator_data[Meter][sensor.meter_1_temperature-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'temperature',
|
||||
@@ -161,7 +161,7 @@
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info1-1][sensor.meter_1_battery-entry]
|
||||
# name: test_no_coordinator_data[Plug Mini (EU)][sensor.meter_1_current-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
@@ -176,113 +176,7 @@
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.meter_1_battery',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.BATTERY: 'battery'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Battery',
|
||||
'platform': 'switchbot_cloud',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'meter-id-1_battery',
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info1-1][sensor.meter_1_battery-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'battery',
|
||||
'friendly_name': 'meter-1 Battery',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': '%',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.meter_1_battery',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '100',
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info1-1][sensor.meter_1_humidity-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.meter_1_humidity',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.HUMIDITY: 'humidity'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Humidity',
|
||||
'platform': 'switchbot_cloud',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'meter-id-1_humidity',
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info1-1][sensor.meter_1_humidity-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'humidity',
|
||||
'friendly_name': 'meter-1 Humidity',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': '%',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.meter_1_humidity',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '32',
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info1-1][sensor.meter_1_temperature-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.meter_1_temperature',
|
||||
'entity_id': 'sensor.meter_1_current',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
@@ -292,44 +186,44 @@
|
||||
'name': None,
|
||||
'options': dict({
|
||||
'sensor': dict({
|
||||
'suggested_display_precision': 1,
|
||||
'suggested_display_precision': 0,
|
||||
}),
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.TEMPERATURE: 'temperature'>,
|
||||
'original_device_class': <SensorDeviceClass.CURRENT: 'current'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Temperature',
|
||||
'original_name': 'Current',
|
||||
'platform': 'switchbot_cloud',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'meter-id-1_temperature',
|
||||
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
|
||||
'unique_id': 'meter-id-1_electricCurrent',
|
||||
'unit_of_measurement': <UnitOfElectricCurrent.MILLIAMPERE: 'mA'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info1-1][sensor.meter_1_temperature-state]
|
||||
# name: test_no_coordinator_data[Plug Mini (EU)][sensor.meter_1_current-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'temperature',
|
||||
'friendly_name': 'meter-1 Temperature',
|
||||
'device_class': 'current',
|
||||
'friendly_name': 'meter-1 Current',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
|
||||
'unit_of_measurement': <UnitOfElectricCurrent.MILLIAMPERE: 'mA'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.meter_1_temperature',
|
||||
'entity_id': 'sensor.meter_1_current',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '21.8',
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info2-2][sensor.contact_sensor_name_battery-entry]
|
||||
# name: test_no_coordinator_data[Plug Mini (EU)][sensor.meter_1_energy-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
@@ -338,164 +232,7 @@
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.contact_sensor_name_battery',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.BATTERY: 'battery'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Battery',
|
||||
'platform': 'switchbot_cloud',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'contact-sensor-id_battery',
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info2-2][sensor.contact_sensor_name_battery-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'battery',
|
||||
'friendly_name': 'contact-sensor-name Battery',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': '%',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.contact_sensor_name_battery',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '60',
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info3-3][sensor.hub_3_name_humidity-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.hub_3_name_humidity',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.HUMIDITY: 'humidity'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Humidity',
|
||||
'platform': 'switchbot_cloud',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'hub3-id_humidity',
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info3-3][sensor.hub_3_name_humidity-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'humidity',
|
||||
'friendly_name': 'Hub-3-name Humidity',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': '%',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.hub_3_name_humidity',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '55',
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info3-3][sensor.hub_3_name_light_level-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.hub_3_name_light_level',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Light level',
|
||||
'platform': 'switchbot_cloud',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'light_level',
|
||||
'unique_id': 'hub3-id_lightLevel',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info3-3][sensor.hub_3_name_light_level-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Hub-3-name Light level',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.hub_3_name_light_level',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '10',
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info3-3][sensor.hub_3_name_temperature-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.hub_3_name_temperature',
|
||||
'entity_id': 'sensor.meter_1_energy',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
@@ -505,38 +242,38 @@
|
||||
'name': None,
|
||||
'options': dict({
|
||||
'sensor': dict({
|
||||
'suggested_display_precision': 1,
|
||||
'suggested_display_precision': 2,
|
||||
}),
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.TEMPERATURE: 'temperature'>,
|
||||
'original_device_class': <SensorDeviceClass.ENERGY: 'energy'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Temperature',
|
||||
'original_name': 'Energy',
|
||||
'platform': 'switchbot_cloud',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'hub3-id_temperature',
|
||||
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
|
||||
'unique_id': 'meter-id-1_usedElectricity',
|
||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info3-3][sensor.hub_3_name_temperature-state]
|
||||
# name: test_no_coordinator_data[Plug Mini (EU)][sensor.meter_1_energy-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'temperature',
|
||||
'friendly_name': 'Hub-3-name Temperature',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
|
||||
'device_class': 'energy',
|
||||
'friendly_name': 'meter-1 Energy',
|
||||
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.hub_3_name_temperature',
|
||||
'entity_id': 'sensor.meter_1_energy',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '26.5',
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info4-4][sensor.motion_sensor_name_battery-entry]
|
||||
# name: test_no_coordinator_data[Plug Mini (EU)][sensor.meter_1_power-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
@@ -551,7 +288,7 @@
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.motion_sensor_name_battery',
|
||||
'entity_id': 'sensor.meter_1_power',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
@@ -560,36 +297,39 @@
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
'sensor': dict({
|
||||
'suggested_display_precision': 0,
|
||||
}),
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.BATTERY: 'battery'>,
|
||||
'original_device_class': <SensorDeviceClass.POWER: 'power'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Battery',
|
||||
'original_name': 'Power',
|
||||
'platform': 'switchbot_cloud',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'motion-sensor-id_battery',
|
||||
'unit_of_measurement': '%',
|
||||
'unique_id': 'meter-id-1_power',
|
||||
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info4-4][sensor.motion_sensor_name_battery-state]
|
||||
# name: test_no_coordinator_data[Plug Mini (EU)][sensor.meter_1_power-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'battery',
|
||||
'friendly_name': 'motion-sensor-name Battery',
|
||||
'device_class': 'power',
|
||||
'friendly_name': 'meter-1 Power',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': '%',
|
||||
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.motion_sensor_name_battery',
|
||||
'entity_id': 'sensor.meter_1_power',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '20',
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info5-5][sensor.water_detector_name_battery-entry]
|
||||
# name: test_no_coordinator_data[Plug Mini (EU)][sensor.meter_1_voltage-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
@@ -604,7 +344,7 @@
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.water_detector_name_battery',
|
||||
'entity_id': 'sensor.meter_1_voltage',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
@@ -613,32 +353,35 @@
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
'sensor': dict({
|
||||
'suggested_display_precision': 0,
|
||||
}),
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.BATTERY: 'battery'>,
|
||||
'original_device_class': <SensorDeviceClass.VOLTAGE: 'voltage'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Battery',
|
||||
'original_name': 'Voltage',
|
||||
'platform': 'switchbot_cloud',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'water-detector-id_battery',
|
||||
'unit_of_measurement': '%',
|
||||
'unique_id': 'meter-id-1_voltage',
|
||||
'unit_of_measurement': <UnitOfElectricPotential.VOLT: 'V'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_meter[device_info5-5][sensor.water_detector_name_battery-state]
|
||||
# name: test_no_coordinator_data[Plug Mini (EU)][sensor.meter_1_voltage-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'battery',
|
||||
'friendly_name': 'water-detector-name Battery',
|
||||
'device_class': 'voltage',
|
||||
'friendly_name': 'meter-1 Voltage',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': '%',
|
||||
'unit_of_measurement': <UnitOfElectricPotential.VOLT: 'V'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.water_detector_name_battery',
|
||||
'entity_id': 'sensor.meter_1_voltage',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '90',
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
|
||||
@@ -6,7 +6,7 @@ import pytest
|
||||
from switchbot_api import Device
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.switchbot_cloud.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@@ -20,7 +20,7 @@ from . import (
|
||||
configure_integration,
|
||||
)
|
||||
|
||||
from tests.common import async_load_json_array_fixture, snapshot_platform
|
||||
from tests.common import snapshot_platform
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -45,10 +45,65 @@ async def test_meter(
|
||||
) -> None:
|
||||
"""Test all sensors."""
|
||||
|
||||
mock_list_devices.return_value = [device_info]
|
||||
|
||||
json_data = await async_load_json_array_fixture(hass, "status.json", DOMAIN)
|
||||
mock_get_status.return_value = json_data[index]
|
||||
async def test_plug_mini_eu(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
mock_list_devices,
|
||||
mock_get_status,
|
||||
) -> None:
|
||||
"""Test plug_mini_eu Used Electricity."""
|
||||
|
||||
mock_list_devices.return_value = [
|
||||
Device(
|
||||
version="V1.0",
|
||||
deviceId="Plug-id-1",
|
||||
deviceName="Plug-1",
|
||||
deviceType="Plug Mini (EU)",
|
||||
hubDeviceId="test-hub-id",
|
||||
),
|
||||
]
|
||||
mock_get_status.side_effect = [
|
||||
{
|
||||
"usedElectricity": 3255,
|
||||
"deviceId": "94A99054855E",
|
||||
"deviceType": "Plug Mini (EU)",
|
||||
},
|
||||
]
|
||||
|
||||
with patch("homeassistant.components.switchbot_cloud.PLATFORMS", [Platform.SENSOR]):
|
||||
entry = await configure_integration(hass)
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"device_model",
|
||||
[
|
||||
"Meter",
|
||||
"Plug Mini (EU)",
|
||||
],
|
||||
)
|
||||
async def test_no_coordinator_data(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
mock_list_devices,
|
||||
mock_get_status,
|
||||
device_model,
|
||||
) -> None:
|
||||
"""Test meter sensors are unknown without coordinator data."""
|
||||
mock_list_devices.return_value = [
|
||||
Device(
|
||||
version="V1.0",
|
||||
deviceId="meter-id-1",
|
||||
deviceName="meter-1",
|
||||
deviceType=device_model,
|
||||
hubDeviceId="test-hub-id",
|
||||
),
|
||||
]
|
||||
|
||||
mock_get_status.return_value = None
|
||||
|
||||
with patch("homeassistant.components.switchbot_cloud.PLATFORMS", [Platform.SENSOR]):
|
||||
entry = await configure_integration(hass)
|
||||
|
||||
Reference in New Issue
Block a user