mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add Switchbot Hub 2, Switchbot Meter Pro and Switchbot Meter Pro (CO2) devices to Switchbot Cloud integration. (#130295)
This commit is contained in:
parent
41c6eeedca
commit
388c5807ea
@ -85,6 +85,9 @@ def make_device_data(
|
|||||||
"Meter",
|
"Meter",
|
||||||
"MeterPlus",
|
"MeterPlus",
|
||||||
"WoIOSensor",
|
"WoIOSensor",
|
||||||
|
"Hub 2",
|
||||||
|
"MeterPro",
|
||||||
|
"MeterPro(CO2)",
|
||||||
]:
|
]:
|
||||||
devices_data.sensors.append(
|
devices_data.sensors.append(
|
||||||
prepare_device(hass, api, device, coordinators_by_id)
|
prepare_device(hass, api, device, coordinators_by_id)
|
||||||
|
@ -9,7 +9,11 @@ from homeassistant.components.sensor import (
|
|||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import PERCENTAGE, UnitOfTemperature
|
from homeassistant.const import (
|
||||||
|
CONCENTRATION_PARTS_PER_MILLION,
|
||||||
|
PERCENTAGE,
|
||||||
|
UnitOfTemperature,
|
||||||
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
@ -21,6 +25,7 @@ from .entity import SwitchBotCloudEntity
|
|||||||
SENSOR_TYPE_TEMPERATURE = "temperature"
|
SENSOR_TYPE_TEMPERATURE = "temperature"
|
||||||
SENSOR_TYPE_HUMIDITY = "humidity"
|
SENSOR_TYPE_HUMIDITY = "humidity"
|
||||||
SENSOR_TYPE_BATTERY = "battery"
|
SENSOR_TYPE_BATTERY = "battery"
|
||||||
|
SENSOR_TYPE_CO2 = "CO2"
|
||||||
|
|
||||||
METER_PLUS_SENSOR_DESCRIPTIONS = (
|
METER_PLUS_SENSOR_DESCRIPTIONS = (
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
@ -43,6 +48,16 @@ METER_PLUS_SENSOR_DESCRIPTIONS = (
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
METER_PRO_CO2_SENSOR_DESCRIPTIONS = (
|
||||||
|
*METER_PLUS_SENSOR_DESCRIPTIONS,
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=SENSOR_TYPE_CO2,
|
||||||
|
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
device_class=SensorDeviceClass.CO2,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -55,7 +70,11 @@ async def async_setup_entry(
|
|||||||
async_add_entities(
|
async_add_entities(
|
||||||
SwitchBotCloudSensor(data.api, device, coordinator, description)
|
SwitchBotCloudSensor(data.api, device, coordinator, description)
|
||||||
for device, coordinator in data.devices.sensors
|
for device, coordinator in data.devices.sensors
|
||||||
for description in METER_PLUS_SENSOR_DESCRIPTIONS
|
for description in (
|
||||||
|
METER_PRO_CO2_SENSOR_DESCRIPTIONS
|
||||||
|
if device.device_type == "MeterPro(CO2)"
|
||||||
|
else METER_PLUS_SENSOR_DESCRIPTIONS
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,6 +50,18 @@ async def test_setup_entry_success(
|
|||||||
remoteType="DIY Plug",
|
remoteType="DIY Plug",
|
||||||
hubDeviceId="test-hub-id",
|
hubDeviceId="test-hub-id",
|
||||||
),
|
),
|
||||||
|
Remote(
|
||||||
|
deviceId="meter-pro-1",
|
||||||
|
deviceName="meter-pro-name-1",
|
||||||
|
deviceType="MeterPro(CO2)",
|
||||||
|
hubDeviceId="test-hub-id",
|
||||||
|
),
|
||||||
|
Remote(
|
||||||
|
deviceId="hub2-1",
|
||||||
|
deviceName="hub2-name-1",
|
||||||
|
deviceType="Hub 2",
|
||||||
|
hubDeviceId="test-hub-id",
|
||||||
|
),
|
||||||
]
|
]
|
||||||
mock_get_status.return_value = {"power": PowerState.ON.value}
|
mock_get_status.return_value = {"power": PowerState.ON.value}
|
||||||
entry = configure_integration(hass)
|
entry = configure_integration(hass)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user