Skip to content

Commit f113a89

Browse files
committed
event.fire and state.set send context if provided
1 parent d0745ea commit f113a89

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

custom_components/pyscript/function.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ async def async_sleep(cls, duration):
117117
@classmethod
118118
async def event_fire(cls, event_type, **kwargs):
119119
"""Implement event.fire()."""
120-
cls.hass.bus.async_fire(event_type, kwargs)
120+
if "context" in kwargs and isinstance(kwargs["context"], Context):
121+
context = kwargs["context"]
122+
del kwargs["context"]
123+
cls.hass.bus.async_fire(event_type, kwargs, context=context)
124+
else:
125+
cls.hass.bus.async_fire(event_type, kwargs)
121126

122127
@classmethod
123128
def task_unique_factory(cls, ctx):

custom_components/pyscript/state.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44

55
from homeassistant.helpers.restore_state import RestoreStateData
6+
from homeassistant.core import Context
67

78
from .const import LOGGER_PATH
89
from .function import Function
@@ -115,13 +116,19 @@ async def set(cls, var_name, value, new_attributes=None, **kwargs):
115116
new_attributes = state_value.attributes
116117
else:
117118
new_attributes = {}
119+
120+
context = None
121+
if "context" in kwargs and isinstance(kwargs["context"], Context):
122+
context = kwargs["context"]
123+
del kwargs["context"]
124+
118125
if kwargs:
119126
new_attributes = new_attributes.copy()
120127
new_attributes.update(kwargs)
121128
_LOGGER.debug("setting %s = %s, attr = %s", var_name, value, new_attributes)
122129
cls.notify_var_last[var_name] = str(value)
123130

124-
cls.hass.states.async_set(var_name, value, new_attributes)
131+
cls.hass.states.async_set(var_name, value, new_attributes, context=context)
125132

126133
@classmethod
127134
async def register_persist(cls, var_name):

0 commit comments

Comments
 (0)