Skip to content

Commit

Permalink
fix(type_controller): call render_template before calling get_state
Browse files Browse the repository at this point in the history
related to #305
  • Loading branch information
xaviml committed May 21, 2021
1 parent e68e0d5 commit 2935827
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PRERELEASE_NOTE

## :hammer: Fixes

- Fix Z2M mapping for [W2049](https://xaviml.github.io/controllerx/controllers/W2049) [ #292 ]
- ValueError when render template is present in the entity name [ #305 ]

<!--
## :clock2: Performance
Expand All @@ -24,7 +24,9 @@ PRERELEASE_NOTE
## :wrench: Refactor
-->

<!--
## :video_game: New devices
- [929003017102](https://xaviml.github.io/controllerx/controllers/929003017102) - add device with Z2M and deCONZ support [ #276 ]
- [E1812](https://xaviml.github.io/controllerx/controllers/E1812) - add deCONZ support [ #296 ] @schneekluth
-->
11 changes: 11 additions & 0 deletions apps/controllerx/cx_core/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,17 @@ async def call_service(self, service: str, **attributes) -> Optional[Any]:
self.log("\n".join(to_log), level="INFO", ascii_encode=False)
return await Hass.call_service(self, service, **attributes) # type: ignore

async def get_state(
self,
entity_id: Optional[str] = None,
attribute: Optional[str] = None,
default: Any = None,
copy: bool = True,
**kwargs,
) -> Optional[Any]:
rendered_entity_id = await self.render_value(entity_id)
return await super().get_state(rendered_entity_id, attribute, default, copy, **kwargs) # type: ignore

async def handle_action(
self, action_key: str, extra: Optional[EventData] = None
) -> None:
Expand Down
4 changes: 2 additions & 2 deletions apps/controllerx/cx_core/type_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def check_domain(self, entity_name: str) -> None:
if self.contains_templating(entity_name):
return
elif entity_name.startswith("group."):
entities = await self.get_state(entity_name, attribute="entity_id") # type: ignore
entities: List[str] = await self.get_state(entity_name, attribute="entity_id") # type: ignore
same_domain = all(
(
any(elem.startswith(domain + ".") for domain in self.domains)
Expand All @@ -78,7 +78,7 @@ async def get_entity_state(
self, entity: str, attribute: Optional[str] = None
) -> Any:
if entity.startswith("group."):
entities = await self.get_state(entity, attribute="entity_id") # type: ignore
entities: List[str] = await self.get_state(entity, attribute="entity_id") # type: ignore
if len(entities) == 0:
raise ValueError(
f"The group `{entity}` does not have any entities registered."
Expand Down

0 comments on commit 2935827

Please sign in to comment.