Broadlink, remove attr_current_power_w and add sensor (#53342)

This commit is contained in:
Daniel Hjelseth Høyer 2021-07-26 17:42:19 +02:00 committed by GitHub
parent 37d6824ed4
commit d58a02a647
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 4 deletions

View File

@ -7,7 +7,16 @@ DOMAIN = "broadlink"
DOMAINS_AND_TYPES = {
REMOTE_DOMAIN: {"RM4MINI", "RM4PRO", "RMMINI", "RMMINIB", "RMPRO"},
SENSOR_DOMAIN: {"A1", "RM4MINI", "RM4PRO", "RMPRO"},
SENSOR_DOMAIN: {
"A1",
"RM4MINI",
"RM4PRO",
"RMPRO",
"SP2S",
"SP3S",
"SP4",
"SP4B",
},
SWITCH_DOMAIN: {
"BG1",
"MP1",

View File

@ -6,12 +6,13 @@ import voluptuous as vol
from homeassistant.components.sensor import (
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE,
PLATFORM_SCHEMA,
STATE_CLASS_MEASUREMENT,
SensorEntity,
)
from homeassistant.const import CONF_HOST, PERCENTAGE, TEMP_CELSIUS
from homeassistant.const import CONF_HOST, PERCENTAGE, POWER_WATT, TEMP_CELSIUS
from homeassistant.core import callback
from homeassistant.helpers import config_validation as cv
@ -37,6 +38,12 @@ SENSOR_TYPES = {
),
"light": ("Light", None, DEVICE_CLASS_ILLUMINANCE, None),
"noise": ("Noise", None, None, None),
"power": (
"Current power",
POWER_WATT,
DEVICE_CLASS_POWER,
STATE_CLASS_MEASUREMENT,
),
}
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(

View File

@ -232,14 +232,12 @@ class BroadlinkSP2Switch(BroadlinkSP1Switch):
"""Initialize the switch."""
super().__init__(device, *args, **kwargs)
self._attr_is_on = self._coordinator.data["pwr"]
self._attr_current_power_w = self._coordinator.data.get("power")
@callback
def update_data(self):
"""Update data."""
if self._coordinator.last_update_success:
self._attr_is_on = self._coordinator.data["pwr"]
self._attr_current_power_w = self._coordinator.data.get("power")
self.async_write_ha_state()