diff --git a/homeassistant/components/smartthings/climate.py b/homeassistant/components/smartthings/climate.py index 9bc287b054c..87d20b4533f 100644 --- a/homeassistant/components/smartthings/climate.py +++ b/homeassistant/components/smartthings/climate.py @@ -106,7 +106,6 @@ def get_capabilities(capabilities: Sequence[str]) -> Sequence[str] | None: Capability.air_conditioner_mode, Capability.demand_response_load_control, Capability.air_conditioner_fan_mode, - Capability.power_consumption_report, Capability.relative_humidity_measurement, Capability.switch, Capability.temperature_measurement, @@ -422,10 +421,6 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateEntity): "drlc_status_level", "drlc_status_start", "drlc_status_override", - "power_consumption_start", - "power_consumption_power", - "power_consumption_energy", - "power_consumption_end", ] state_attributes = {} for attribute in attributes: diff --git a/homeassistant/components/smartthings/sensor.py b/homeassistant/components/smartthings/sensor.py index 872921199f0..64869347228 100644 --- a/homeassistant/components/smartthings/sensor.py +++ b/homeassistant/components/smartthings/sensor.py @@ -553,7 +553,7 @@ async def async_setup_entry( config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: - """Add binary sensors for a config entry.""" + """Add sensors for a config entry.""" broker = hass.data[DOMAIN][DATA_BROKERS][config_entry.entry_id] entities: list[SensorEntity] = [] for device in broker.devices.values(): @@ -641,7 +641,7 @@ class SmartThingsSensor(SmartThingsEntity, SensorEntity): @property def name(self) -> str: - """Return the name of the binary sensor.""" + """Return the name of the sensor.""" return f"{self._device.label} {self._name}" @property @@ -681,7 +681,7 @@ class SmartThingsThreeAxisSensor(SmartThingsEntity, SensorEntity): @property def name(self) -> str: - """Return the name of the binary sensor.""" + """Return the name of the sensor.""" return f"{self._device.label} {THREE_AXIS_NAMES[self._index]}" @property @@ -716,7 +716,7 @@ class SmartThingsPowerConsumptionSensor(SmartThingsEntity, SensorEntity): @property def name(self) -> str: - """Return the name of the binary sensor.""" + """Return the name of the sensor.""" return f"{self._device.label} {self.report_name}" @property @@ -747,3 +747,19 @@ class SmartThingsPowerConsumptionSensor(SmartThingsEntity, SensorEntity): if self.report_name == "power": return POWER_WATT return ENERGY_KILO_WATT_HOUR + + @property + def extra_state_attributes(self): + """Return specific state attributes.""" + if self.report_name == "power": + attributes = [ + "power_consumption_start", + "power_consumption_end", + ] + state_attributes = {} + for attribute in attributes: + value = getattr(self._device.status, attribute) + if value is not None: + state_attributes[attribute] = value + return state_attributes + return None diff --git a/tests/components/smartthings/test_climate.py b/tests/components/smartthings/test_climate.py index 5c3d61d8b41..825b8259276 100644 --- a/tests/components/smartthings/test_climate.py +++ b/tests/components/smartthings/test_climate.py @@ -148,7 +148,6 @@ def air_conditioner_fixture(device_factory): Capability.air_conditioner_mode, Capability.demand_response_load_control, Capability.air_conditioner_fan_mode, - Capability.power_consumption_report, Capability.switch, Capability.temperature_measurement, Capability.thermostat_cooling_setpoint, @@ -177,12 +176,6 @@ def air_conditioner_fixture(device_factory): "high", "turbo", ], - Attribute.power_consumption: { - "start": "2019-02-24T21:03:04Z", - "power": 0, - "energy": 500, - "end": "2019-02-26T02:05:55Z", - }, Attribute.switch: "on", Attribute.cooling_setpoint: 23, }, @@ -320,10 +313,6 @@ async def test_air_conditioner_entity_state(hass, air_conditioner): assert state.attributes["drlc_status_level"] == -1 assert state.attributes["drlc_status_start"] == "1970-01-01T00:00:00Z" assert state.attributes["drlc_status_override"] is False - assert state.attributes["power_consumption_start"] == "2019-02-24T21:03:04Z" - assert state.attributes["power_consumption_power"] == 0 - assert state.attributes["power_consumption_energy"] == 500 - assert state.attributes["power_consumption_end"] == "2019-02-26T02:05:55Z" async def test_set_fan_mode(hass, thermostat, air_conditioner): diff --git a/tests/components/smartthings/test_sensor.py b/tests/components/smartthings/test_sensor.py index 98464af24af..a4e89ebe5c7 100644 --- a/tests/components/smartthings/test_sensor.py +++ b/tests/components/smartthings/test_sensor.py @@ -190,6 +190,8 @@ async def test_power_consumption_sensor(hass, device_factory): state = hass.states.get("sensor.refrigerator_power") assert state assert state.state == "109" + assert state.attributes["power_consumption_start"] == "2021-07-30T16:45:25Z" + assert state.attributes["power_consumption_end"] == "2021-07-30T16:58:33Z" entry = entity_registry.async_get("sensor.refrigerator_power") assert entry assert entry.unique_id == f"{device.device_id}.power_meter"