mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Restore missing device_class to template binary_sensor (#39805)
This commit is contained in:
parent
fa07787007
commit
f1de903fb5
@ -194,3 +194,8 @@ class BinarySensorTemplate(TemplateEntity, BinarySensorEntity):
|
|||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if sensor is on."""
|
"""Return true if sensor is on."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return the sensor class of the binary sensor."""
|
||||||
|
return self._device_class
|
||||||
|
@ -6,6 +6,7 @@ from unittest import mock
|
|||||||
|
|
||||||
from homeassistant import setup
|
from homeassistant import setup
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
ATTR_DEVICE_CLASS,
|
||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
@ -411,7 +412,10 @@ async def test_available_without_availability_template(hass):
|
|||||||
await hass.async_start()
|
await hass.async_start()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("binary_sensor.test").state != STATE_UNAVAILABLE
|
state = hass.states.get("binary_sensor.test")
|
||||||
|
|
||||||
|
assert state.state != STATE_UNAVAILABLE
|
||||||
|
assert state.attributes[ATTR_DEVICE_CLASS] == "motion"
|
||||||
|
|
||||||
|
|
||||||
async def test_availability_template(hass):
|
async def test_availability_template(hass):
|
||||||
@ -443,7 +447,10 @@ async def test_availability_template(hass):
|
|||||||
hass.states.async_set("sensor.test_state", STATE_ON)
|
hass.states.async_set("sensor.test_state", STATE_ON)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("binary_sensor.test").state != STATE_UNAVAILABLE
|
state = hass.states.get("binary_sensor.test")
|
||||||
|
|
||||||
|
assert state.state != STATE_UNAVAILABLE
|
||||||
|
assert state.attributes[ATTR_DEVICE_CLASS] == "motion"
|
||||||
|
|
||||||
|
|
||||||
async def test_invalid_attribute_template(hass, caplog):
|
async def test_invalid_attribute_template(hass, caplog):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user