Home Assistant Unofficial Reference 2024.12.1
homeassistant.components.python_script Namespace Reference

Classes

class  ScriptError
 
class  StubPrinter
 
class  TimeWrapper
 

Functions

None discover_scripts (HomeAssistant hass)
 
def execute (hass, filename, source, data=None, return_response=False)
 
def execute_script (hass, name, data=None, return_response=False)
 
Any guarded_inplacevar (str op, Any target, Any operand)
 
bool setup (HomeAssistant hass, ConfigType config)
 

Variables

 _LOGGER = logging.getLogger(__name__)
 
dictionary ALLOWED_DATETIME = {"date", "time", "datetime", "timedelta", "tzinfo"}
 
dictionary ALLOWED_DT_UTIL
 
dictionary ALLOWED_EVENTBUS = {"fire"}
 
dictionary ALLOWED_HASS = {"bus", "services", "states"}
 
dictionary ALLOWED_SERVICEREGISTRY = {"services", "has_service", "call"}
 
dictionary ALLOWED_STATEMACHINE
 
dictionary ALLOWED_TIME
 
string CONF_FIELDS = "fields"
 
 CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema(dict)}, extra=vol.ALLOW_EXTRA)
 
string DOMAIN = "python_script"
 
string FOLDER = "python_scripts"
 
dictionary IOPERATOR_TO_OPERATOR
 

Detailed Description

Component to allow running Python scripts.

Function Documentation

◆ discover_scripts()

None homeassistant.components.python_script.discover_scripts ( HomeAssistant  hass)
Discover python scripts in folder.

Definition at line 111 of file __init__.py.

◆ execute()

def homeassistant.components.python_script.execute (   hass,
  filename,
  source,
  data = None,
  return_response = False 
)
Execute Python source.

Definition at line 194 of file __init__.py.

◆ execute_script()

def homeassistant.components.python_script.execute_script (   hass,
  name,
  data = None,
  return_response = False 
)
Execute a script.

Definition at line 184 of file __init__.py.

◆ guarded_inplacevar()

Any homeassistant.components.python_script.guarded_inplacevar ( str  op,
Any  target,
Any  operand 
)
Implement augmented-assign (+=, -=, etc.) operators for restricted code.

See RestrictedPython's `visit_AugAssign` for details.

Definition at line 170 of file __init__.py.

◆ setup()

bool homeassistant.components.python_script.setup ( HomeAssistant  hass,
ConfigType  config 
)
Initialize the Python script component.

Definition at line 92 of file __init__.py.

Variable Documentation

◆ _LOGGER

homeassistant.components.python_script._LOGGER = logging.getLogger(__name__)
private

Definition at line 41 of file __init__.py.

◆ ALLOWED_DATETIME

dictionary homeassistant.components.python_script.ALLOWED_DATETIME = {"date", "time", "datetime", "timedelta", "tzinfo"}

Definition at line 71 of file __init__.py.

◆ ALLOWED_DT_UTIL

dictionary homeassistant.components.python_script.ALLOWED_DT_UTIL
Initial value:
1 = {
2  "utcnow",
3  "now",
4  "as_utc",
5  "as_timestamp",
6  "as_local",
7  "utc_from_timestamp",
8  "start_of_local_day",
9  "parse_datetime",
10  "parse_date",
11  "get_age",
12 }

Definition at line 72 of file __init__.py.

◆ ALLOWED_EVENTBUS

dictionary homeassistant.components.python_script.ALLOWED_EVENTBUS = {"fire"}

Definition at line 50 of file __init__.py.

◆ ALLOWED_HASS

dictionary homeassistant.components.python_script.ALLOWED_HASS = {"bus", "services", "states"}

Definition at line 49 of file __init__.py.

◆ ALLOWED_SERVICEREGISTRY

dictionary homeassistant.components.python_script.ALLOWED_SERVICEREGISTRY = {"services", "has_service", "call"}

Definition at line 60 of file __init__.py.

◆ ALLOWED_STATEMACHINE

dictionary homeassistant.components.python_script.ALLOWED_STATEMACHINE
Initial value:
1 = {
2  "entity_ids",
3  "all",
4  "get",
5  "is_state",
6  "is_state_attr",
7  "remove",
8  "set",
9 }

Definition at line 51 of file __init__.py.

◆ ALLOWED_TIME

dictionary homeassistant.components.python_script.ALLOWED_TIME
Initial value:
1 = {
2  "sleep",
3  "strftime",
4  "strptime",
5  "gmtime",
6  "localtime",
7  "ctime",
8  "time",
9  "mktime",
10 }

Definition at line 61 of file __init__.py.

◆ CONF_FIELDS

string homeassistant.components.python_script.CONF_FIELDS = "fields"

Definition at line 85 of file __init__.py.

◆ CONFIG_SCHEMA

homeassistant.components.python_script.CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema(dict)}, extra=vol.ALLOW_EXTRA)

Definition at line 47 of file __init__.py.

◆ DOMAIN

string homeassistant.components.python_script.DOMAIN = "python_script"

Definition at line 43 of file __init__.py.

◆ FOLDER

string homeassistant.components.python_script.FOLDER = "python_scripts"

Definition at line 45 of file __init__.py.

◆ IOPERATOR_TO_OPERATOR

dictionary homeassistant.components.python_script.IOPERATOR_TO_OPERATOR
Initial value:
1 = {
2  "%=": operator.mod,
3  "&=": operator.and_,
4  "**=": operator.pow,
5  "*=": operator.mul,
6  "+=": operator.add,
7  "-=": operator.sub,
8  "//=": operator.floordiv,
9  "/=": operator.truediv,
10  "<<=": operator.lshift,
11  ">>=": operator.rshift,
12  "@=": operator.matmul,
13  "^=": operator.xor,
14  "|=": operator.or_,
15 }

Definition at line 153 of file __init__.py.