dependencies module¶
Action Engine¶
ActionEngine for HomeControl
Configuration Manager¶
config_manager module
-
class
homecontrol.dependencies.config_manager.ConfigManager(cfg: dict, cfg_path: str)[source]¶ Bases:
objectManages the configuration with configuration domains
-
coroutine
approve_domain_config(domain: str, config: dict, initial: bool = True) → dict[source]¶ Returns an approved and validated version of config for a domain
-
coroutine
register_domain(domain: str, handler: object = None, schema: voluptuous.schema_builder.Schema = None, allow_reload: bool = False, default: dict = None) → object[source]¶ Registers a configuration domain
Objects can register themselves to their own configuration domain and subscribe to changes in the configuration
Parameters: - domain (str) – The configuration domain (A top-level key in config.yaml)
- handler (object) – The object subscribing to this domain. Methods it can implement are: - approve_configuration(domain, config) -> bool: - apply_new_configuration(domain, config) -> None: If not specified then your configuration domain will not be reloadable
- allow_reload (bool):
- Allow reloading this configuration domain
- schema (voluptuous.Schema):
- Schema to validate the configuration and to fill in defaults
- default (dict):
- A default configuration
Returns: A validated and approved version of the configuration
-
coroutine
Data Types¶
data types for HomeControl that can be translated to JSON for API usage
-
class
homecontrol.dependencies.data_types.Color(h: int, s: int, l: int)[source]¶ Bases:
objectRepresentation for a color
-
dump() -> (<class 'int'>, <class 'int'>, <class 'int'>)[source]¶ Dumps the Color into a JSON serialisable format
-
staticmethod
from_data(hsl: tuple)[source]¶ Constructor from the data received through the API or configuration
-
h¶ Hue
-
l¶ Lightness
-
rgb¶ RGB
-
s¶ Saturation
-
Entity Types¶
Module containing the entity types Every new Item or Module will get one of these classes as a base class
-
class
homecontrol.dependencies.entity_types.Item[source]¶ Bases:
objectA dummy Item
-
config_schema= <Schema(<class 'object'>, extra=PREVENT_EXTRA, required=False) object>¶
-
coroutine
constructor(identifier: str, name: str, cfg: dict, state_defaults: dict, core: homecontrol.core.Core) → Item[source]¶ Constructs an item
-
status= 'offline'¶
-
-
class
homecontrol.dependencies.entity_types.Module[source]¶ Bases:
objectA dummy Module
-
folder_location= None¶
-
-
homecontrol.dependencies.entity_types.ModuleDef¶
Event Engine¶
EventEngine for HomeControl
-
class
homecontrol.dependencies.event_engine.Event(event_type: str, data: dict = None, timestamp: int = None, kwargs: dict = None)[source]¶ Bases:
objectRepresentation for an Event
-
class
homecontrol.dependencies.event_engine.EventEngine(core)[source]¶ Bases:
objectDispatcher for events
-
broadcast(event_type: str, data: dict = None, **kwargs) → List[_asyncio.Future][source]¶ Broadcast an event and return the futures
Every listener is a coroutine that will simply receive event and kwargs
Example: >>> async def on_event(event: Event, …): >>> return
-
broadcast_threaded(event_type: str, data: dict = None, **kwargs) → List[_asyncio.Task][source]¶ Same as broadcast BUT - It returns Futures and not Tasks - It uses threads
-
staticmethod
create_event(event_type: str, data: dict = None, **kwargs) → homecontrol.dependencies.event_engine.Event[source]¶ Creates an Event to be broadcasted
-
coroutine
gather(event_type: str, data: dict = None, timeout: Union[float, int, None] = None, **kwargs) → List[Any][source]¶ Broadcast an event and return the results
-
Item Manager¶
ItemManager for HomeControl
-
class
homecontrol.dependencies.item_manager.ItemManager(core)[source]¶ Bases:
objectItemManager manages all your stateful items
-
coroutine
add_from_module(mod_obj: homecontrol.dependencies.entity_types.Module) → None[source]¶ Adds the item specifications of a module to the dict of available ones
mod_obj: homecontrol.entity_types.Module
-
coroutine
create_from_storage_entry(storage_entry: dict) → homecontrol.dependencies.entity_types.Item[source]¶ Creates an Item from a storage entry
-
coroutine
create_item(identifier: str, item_type: str, cfg: dict = None, state_defaults: dict = None, name: str = None) → homecontrol.dependencies.entity_types.Item[source]¶ Creates a HomeControl item
-
coroutine
init_item(item: homecontrol.dependencies.entity_types.Item) → None[source]¶ Initialises an item
-
for ... in
iter_items_by_id(iterable) → [<class 'homecontrol.dependencies.entity_types.Item'>][source]¶ Translates item identifiers into item instances
-
coroutine
remove_item(identifier: str) → None[source]¶ Removes a HomeControl item
- identifier: str
- The item’s identifier
-
coroutine
JSON Response¶
JSONResponse module
JSON¶
JSON Encoder and Decoder
-
class
homecontrol.dependencies.json.JSONEncoder(core: Core, *args, **kwargs)[source]¶ Bases:
json.encoder.JSONEncoderCustom JSONEncoder that also parses HomeControl types
Module Manager¶
ModuleManager module
-
class
homecontrol.dependencies.module_manager.ModuleFolder(name: str)[source]¶ Bases:
objectmodule folder representation to create a dummy package in sys.modules
-
class
homecontrol.dependencies.module_manager.ModuleManager(core)[source]¶ Bases:
objectManages your modules
-
coroutine
load_file_module(mod_path: str, name: str) -> (<class 'homecontrol.dependencies.entity_types.Module'>, <class 'Exception'>)[source]¶ Loads a module from a file and initialises it
Returns a Module object
-
coroutine
load_folder_module(path: str, name: str) -> (<class 'homecontrol.dependencies.entity_types.Module'>, <class 'Exception'>)[source]¶ Loads a module from a folder and initialises it
It also takes care of pip requirements
Returns a Module object
-
coroutine
State Engine¶
StateEngine module
-
class
homecontrol.dependencies.state_engine.State(state_engine: homecontrol.dependencies.state_engine.StateEngine, default, getter: Callable = None, setter: Callable = None, name: str = None, state_type: type = None, schema: dict = None, poll_interval: float = None)[source]¶ Bases:
objectHolds one state of an item
-
class
homecontrol.dependencies.state_engine.StateDef(poll_interval: Optional[float] = None, default: Any = None, default_factory: Callable = None)[source]¶ Bases:
object
-
class
homecontrol.dependencies.state_engine.StateEngine(item: homecontrol.dependencies.entity_types.Item, core: homecontrol.core.Core, state_defaults: dict = None)[source]¶ Bases:
objectHolds the states of an item
-
check_value(state: str, value) → voluptuous.error.Error[source]¶ Checks if a value is valid for a state
-
Throttle Function¶
throttle_function
Tick Engine¶
TickEngine
Validators¶
YAML Loader¶
Provides a YAML loader
-
class
homecontrol.dependencies.yaml_loader.Constructor[source]¶ Bases:
yaml.constructor.SafeConstructorConstructor for yaml
-
env_var_constructor(node: yaml.nodes.Node) → str[source]¶ Embeds an environment variable !env_var <name> [default]
-
format_string_constructor(node: yaml.nodes.Node = None) → str[source]¶ Renders a format string .. rubric:: Example
!format { template: “Hello {who}”, who: You }
-
include_dir_file_mapped_constructor(node: yaml.nodes.Node = None) → dict[source]¶ !include_dir_file_mapped <folder>
Loads multiple files from a folder and maps their contents to their filenames
-
include_file_constructor(node: yaml.nodes.Node = None) → object[source]¶ !include <path> ~/ for paths relative to your home directory / for absolute paths anything else for paths relative to your config folder
-
include_merge_constructor(node: yaml.nodes.Node = None) -> (<class 'list'>, <class 'dict'>)[source]¶ !include <file|folder> …
Merges file or folder contents
This constructor only works if all the files’ contents are of same type and if this type is either list or dict.
-
listdir_constructor(node: yaml.nodes.Node) → list[source]¶ !listdir <path>
Returns the contents of a directory
-
path_constructor(node: yaml.nodes.Node) → str[source]¶ !path <path> ~/ for paths relative to your home directory / for absolute paths anything else for paths relative to your config folder
-
-
class
homecontrol.dependencies.yaml_loader.YAMLLoader(stream, cfg_folder: str = None)[source]¶ Bases:
yaml.reader.Reader,yaml.scanner.Scanner,yaml.parser.Parser,yaml.composer.Composer,homecontrol.dependencies.yaml_loader.Constructor,yaml.resolver.ResolverLoads YAML with custom constructors