Bump pyswitchbot to 0.65.0 (#146133)

* update pyswitchbot to 0.65.0

* fix relay switch 1pm test

* fix ma to a
This commit is contained in:
Retha Runolfsson 2025-06-05 22:42:24 +08:00 committed by GitHub
parent 0b3b641328
commit fd38d9788d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 54 additions and 9 deletions

View File

@ -41,5 +41,5 @@
"iot_class": "local_push",
"loggers": ["switchbot"],
"quality_scale": "gold",
"requirements": ["PySwitchbot==0.64.1"]
"requirements": ["PySwitchbot==0.65.0"]
}

View File

@ -19,6 +19,7 @@ from homeassistant.const import (
EntityCategory,
UnitOfElectricCurrent,
UnitOfElectricPotential,
UnitOfEnergy,
UnitOfPower,
UnitOfTemperature,
)
@ -94,7 +95,7 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = {
),
"current": SensorEntityDescription(
key="current",
native_unit_of_measurement=UnitOfElectricCurrent.MILLIAMPERE,
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.CURRENT,
),
@ -110,6 +111,12 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = {
device_class=SensorDeviceClass.ENUM,
options=[member.name.lower() for member in AirQualityLevel],
),
"energy": SensorEntityDescription(
key="energy",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
),
}

2
requirements_all.txt generated
View File

@ -81,7 +81,7 @@ PyQRCode==1.2.1
PyRMVtransport==0.3.3
# homeassistant.components.switchbot
PySwitchbot==0.64.1
PySwitchbot==0.65.0
# homeassistant.components.switchmate
PySwitchmate==0.5.1

View File

@ -78,7 +78,7 @@ PyQRCode==1.2.1
PyRMVtransport==0.3.3
# homeassistant.components.switchbot
PySwitchbot==0.64.1
PySwitchbot==0.65.0
# homeassistant.components.syncthru
PySyncThru==0.8.0

View File

@ -1,6 +1,6 @@
"""Test the switchbot sensors."""
from unittest.mock import patch
from unittest.mock import AsyncMock, patch
import pytest
@ -124,14 +124,21 @@ async def test_co2_sensor(hass: HomeAssistant) -> None:
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_relay_switch_1pm_power_sensor(hass: HomeAssistant) -> None:
"""Test setting up creates the power sensor."""
async def test_relay_switch_1pm_sensor(hass: HomeAssistant) -> None:
"""Test setting up creates the relay switch 1PM sensor."""
await async_setup_component(hass, DOMAIN, {})
inject_bluetooth_service_info(hass, WORELAY_SWITCH_1PM_SERVICE_INFO)
with patch(
"switchbot.SwitchbotRelaySwitch.update",
return_value=None,
"homeassistant.components.switchbot.switch.switchbot.SwitchbotRelaySwitch.get_basic_info",
new=AsyncMock(
return_value={
"power": 4.9,
"current": 0.02,
"voltage": 25,
"energy": 0.2,
}
),
):
entry = MockConfigEntry(
domain=DOMAIN,
@ -149,11 +156,42 @@ async def test_relay_switch_1pm_power_sensor(hass: HomeAssistant) -> None:
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert len(hass.states.async_all("sensor")) == 5
power_sensor = hass.states.get("sensor.test_name_power")
power_sensor_attrs = power_sensor.attributes
assert power_sensor.state == "4.9"
assert power_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Power"
assert power_sensor_attrs[ATTR_UNIT_OF_MEASUREMENT] == "W"
assert power_sensor_attrs[ATTR_STATE_CLASS] == "measurement"
voltage_sensor = hass.states.get("sensor.test_name_voltage")
voltage_sensor_attrs = voltage_sensor.attributes
assert voltage_sensor.state == "25"
assert voltage_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Voltage"
assert voltage_sensor_attrs[ATTR_UNIT_OF_MEASUREMENT] == "V"
assert voltage_sensor_attrs[ATTR_STATE_CLASS] == "measurement"
current_sensor = hass.states.get("sensor.test_name_current")
current_sensor_attrs = current_sensor.attributes
assert current_sensor.state == "0.02"
assert current_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Current"
assert current_sensor_attrs[ATTR_UNIT_OF_MEASUREMENT] == "A"
assert current_sensor_attrs[ATTR_STATE_CLASS] == "measurement"
energy_sensor = hass.states.get("sensor.test_name_energy")
energy_sensor_attrs = energy_sensor.attributes
assert energy_sensor.state == "0.2"
assert energy_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Energy"
assert energy_sensor_attrs[ATTR_UNIT_OF_MEASUREMENT] == "kWh"
assert energy_sensor_attrs[ATTR_STATE_CLASS] == "total_increasing"
rssi_sensor = hass.states.get("sensor.test_name_bluetooth_signal")
rssi_sensor_attrs = rssi_sensor.attributes
assert rssi_sensor.state == "-60"
assert rssi_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Bluetooth signal"
assert rssi_sensor_attrs[ATTR_UNIT_OF_MEASUREMENT] == "dBm"
assert rssi_sensor_attrs[ATTR_STATE_CLASS] == "measurement"
assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()