Skip to content

Commit

Permalink
Fix device actions and possibly others
Browse files Browse the repository at this point in the history
  • Loading branch information
Sian-Lee-SA committed Sep 28, 2023
1 parent 58ea639 commit e36fa67
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
**/@eaDir
**/Thumbs.db
**/__pycache__/
.release-it.json
.release-it.json
.vscode
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Switch manager is a centralised component to handle button pushes for your wirel

> I am happy to accept any pull requests for anyone who wishes to submit missing blueprint for switches from this repository as to help eliminate other users from having to build their own.
> There is currently a known issue if trying to use a device action which will be looked into when I find time, You can still achieve all and any automation using a call service instead
#### Youtube demonstration
[![YouTube Introduction](images/youtube-introduction.png)](https://www.youtube.com/watch?v=m2Rlobvo5cI)

Expand Down
22 changes: 14 additions & 8 deletions custom_components/switch_manager/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import time
import time, asyncio
from .const import DOMAIN, LOGGER
from .helpers import format_mqtt_message, get_val_from_str
from homeassistant.core import HomeAssistant, Context, callback
from homeassistant.helpers.script import Script
from homeassistant.helpers.script import Script, async_validate_actions_config
from homeassistant.helpers.condition import async_template as template_condition
from homeassistant.helpers.template import Template
from homeassistant.components.mqtt.client import async_subscribe as mqtt_subscribe
Expand Down Expand Up @@ -189,19 +189,25 @@ def __init__( self, hass: HomeAssistant, switch_id, button_index, index, bluepri

self.script: Script = None
self.active = bool(self.sequence)
asyncio.create_task( self.init_script() )

def _check_conditions( self, data ) -> bool:
return self.blueprint.check_conditions( data )

async def init_script( self ):
if self.active:
sequence = await async_validate_actions_config(
self._hass, cv.SCRIPT_SCHEMA(self.sequence)
)
self.script = Script(
hass=self._hass,
sequence=cv.SCRIPT_SCHEMA(self.sequence),
name=f"{DOMAIN}_{switch_id}_{button_index}_{index}",
sequence=sequence,
name=f"{DOMAIN}_{self.switch_id}_{self.button_index}_{self.index}",
domain=DOMAIN,
logger=LOGGER,
script_mode=self.mode
)

def _check_conditions( self, data ) -> bool:
return self.blueprint.check_conditions( data )


async def run( self, data, context ):
if not self.script:
LOGGER.debug(f'No sequence assigned for switch:{self.switch_id} button:{self.button_index} action:{self.index}')
Expand Down

0 comments on commit e36fa67

Please sign in to comment.