Refactor template components to extract common routines (#27064)

* Added availability_template to Template Cover platform

* Added availability_template to Template Binary Sensor platform

* Added availability_template to Template Fan platform

* Added availability_template to Template Light platform

* Added availability_template to Template Sensor platform

* Added availability_template to Template Switch platform

* Added availability_template to Template Vacuum platform

* Added availability_template to Template Lock platform

* Added to test for invalid values in availability_template

* Black and Lint fix

* black formatting

* Added to test for invalid values in availability_template

* black

* Added to test for invalid values in availability_template

* Added to test for invalid values in availability_template

* simplified exception handler

* Fixed Entity discovery big and coverage

* Added to test for invalid values in availability_template

* flake8

* fixed component ID in test

* Added to test for invalid values in availability_template

* Added to test for invalid values in availability_template

* Made availability_template redering erorr more concise

* Cleaned template setup

* I'll remember to run black every time one of these days...

* Refactored Template initialisation

* Refactored Template initialisation

* Updated AVAILABILITY_TEMPLATE Rendering error

* Updated AVAILABILITY_TEMPLATE Rendering error

* Updated AVAILABILITY_TEMPLATE Rendering error

* Updated AVAILABILITY_TEMPLATE Rendering error

* Updated AVAILABILITY_TEMPLATE Rendering error

* Updated AVAILABILITY_TEMPLATE Rendering error

* Updated AVAILABILITY_TEMPLATE Rendering error

* Updated AVAILABILITY_TEMPLATE Rendering error

* Moved const to package Const.py

* Moved const to package Const.py

* Moved const to package Const.py

* Moved const to package Const.py

* Moved const to package Const.py

* Moved const to package Const.py

* Moved const to package Const.py

* Moved const to package Const.py

* Fix import order (pylint)

* Fix import order (pylint)

* Fix import order (pylint)

* Fix import order (pylint)

* Fix import order (pylint)

* Fix import order (pylint)

* Fix import order (pylint)

* Fixed linting issues

* Moved availability_template rendering to common loop

* Moved availability_template rendering to common loop

* Moved availability_template rendering to common loop

* Moved availability_template rendering to common loop

* Removed 'Magic' string

* Removed 'Magic' string and removed duplicate code

* Removed 'Magic' string

* Removed 'Magic' string

* Brought contant into line

* Refactored availability_tempalte rendering to common loop

* Removed 'Magic' string

* Cleaned up const and compare lowercase result to 'true'

* Cleaned up const and compare lowercase result to 'true'

* Cleaned up const and compare lowercase result to 'true'

* Cleaned up const and compare lowercase result to 'true'

* Cleaned up const and compare lowercase result to 'true'

* Cleaned up const and compare lowercase result to 'true'

* Cleaned up const and compare lowercase result to 'true'

* reverted _available back to boolean

* reverted _available back to boolean

* reverted _available back to boolean

* reverted _available back to boolean

* reverted _available back to boolean

* reverted _available back to boolean

* reverted _available back to boolean

* Fixed tests (magic values and state checks)

* Fixed tests (magic values and state checks)

* Fixed tests (async, magic values and state checks)

* Fixed tests (async, magic values and state checks)

* Fixed tests (async, magic values and state checks)

* Fixed tests (async, magic values and state checks)

* Fixed tests (async, magic values and state checks)

* Removed duplicate

* Clean up and remove debug

* Reverted Dev Container Change
This commit is contained in:
Gil Peeters 2019-11-26 11:30:49 +11:00 committed by Paulus Schoutsen
parent d5db55354e
commit 0088995b98
12 changed files with 202 additions and 276 deletions

View file

@ -377,6 +377,49 @@ class TestTemplateSensor:
state = self.hass.states.get("sensor.test2")
assert "device_class" not in state.attributes
def test_available_template_with_entities(self):
"""Test availability tempalates with values from other entities."""
with assert_setup_component(1):
assert setup_component(
self.hass,
"sensor",
{
"sensor": {
"platform": "template",
"sensors": {
"test_template_sensor": {
"value_template": "{{ states.sensor.test_state.state }}",
"availability_template": "{{ is_state('availability_boolean.state', 'on') }}",
}
},
}
},
)
self.hass.start()
self.hass.block_till_done()
# When template returns true..
self.hass.states.set("availability_boolean.state", STATE_ON)
self.hass.block_till_done()
# Device State should not be unavailable
assert (
self.hass.states.get("sensor.test_template_sensor").state
!= STATE_UNAVAILABLE
)
# When Availability template returns false
self.hass.states.set("availability_boolean.state", STATE_OFF)
self.hass.block_till_done()
# device state should be unavailable
assert (
self.hass.states.get("sensor.test_template_sensor").state
== STATE_UNAVAILABLE
)
async def test_available_template_with_entities(hass):
"""Test availability tempalates with values from other entities."""
@ -511,27 +554,27 @@ async def test_no_template_match_all(hass, caplog):
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 6
assert (
"Template sensor invalid_state has no entity ids "
"Template sensor 'invalid_state' has no entity ids "
"configured to track nor were we able to extract the entities to "
"track from the value template"
) in caplog.text
assert (
"Template sensor invalid_icon has no entity ids "
"Template sensor 'invalid_icon' has no entity ids "
"configured to track nor were we able to extract the entities to "
"track from the icon template"
) in caplog.text
assert (
"Template sensor invalid_entity_picture has no entity ids "
"Template sensor 'invalid_entity_picture' has no entity ids "
"configured to track nor were we able to extract the entities to "
"track from the entity_picture template"
) in caplog.text
assert (
"Template sensor invalid_friendly_name has no entity ids "
"Template sensor 'invalid_friendly_name' has no entity ids "
"configured to track nor were we able to extract the entities to "
"track from the friendly_name template"
) in caplog.text
assert (
"Template sensor invalid_attribute has no entity ids "
"Template sensor 'invalid_attribute' has no entity ids "
"configured to track nor were we able to extract the entities to "
"track from the test_attribute template"
) in caplog.text