diff --git a/homeassistant/components/template/binary_sensor.py b/homeassistant/components/template/binary_sensor.py index bd6cb55b880..2e50448c037 100644 --- a/homeassistant/components/template/binary_sensor.py +++ b/homeassistant/components/template/binary_sensor.py @@ -194,3 +194,8 @@ class BinarySensorTemplate(TemplateEntity, BinarySensorEntity): def is_on(self): """Return true if sensor is on.""" return self._state + + @property + def device_class(self): + """Return the sensor class of the binary sensor.""" + return self._device_class diff --git a/tests/components/template/test_binary_sensor.py b/tests/components/template/test_binary_sensor.py index 7003b55c7ed..f9db8be37c6 100644 --- a/tests/components/template/test_binary_sensor.py +++ b/tests/components/template/test_binary_sensor.py @@ -6,6 +6,7 @@ from unittest import mock from homeassistant import setup from homeassistant.const import ( + ATTR_DEVICE_CLASS, EVENT_HOMEASSISTANT_START, STATE_OFF, STATE_ON, @@ -411,7 +412,10 @@ async def test_available_without_availability_template(hass): await hass.async_start() 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): @@ -443,7 +447,10 @@ async def test_availability_template(hass): hass.states.async_set("sensor.test_state", STATE_ON) 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):