1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Fix command_template sensor value_template not being used if json_attributes set (#90603)

* Allow value_template to be used if json_attributes set

* Set state to None if no value_template and json_attributes used

* Refactor check for no value_template when json_attributes used

* Updated and additional unit test

* Updated to set _attr_native_value and return if value_template is None

* Update unit test docstring

* Updated test docstring based on feedback
This commit is contained in:
Steven Rollason
2023-04-06 20:06:31 +01:00
committed by GitHub
parent fca9052430
commit 2b46734bd3
2 changed files with 26 additions and 1 deletions

View File

@@ -137,8 +137,11 @@ class CommandSensor(SensorEntity):
_LOGGER.warning("Unable to parse output as JSON: %s", value)
else:
_LOGGER.warning("Empty reply found when expecting JSON data")
if self._value_template is None:
self._attr_native_value = None
return
elif self._value_template is not None:
if self._value_template is not None:
self._attr_native_value = (
self._value_template.async_render_with_possible_json_value(
value,