.. warning:: Module developers and users should not access any of these functions or variables. This is listed here for completeness. .. moduleauthor:: Mitch Schwenk <*****@*****.**> :copyright: Copyright 2012-2016 by Yombo. :license: LICENSE for details. """ # Import Yombo libraries from yombo.core.exceptions import YomboWarning from yombo.core.library import YomboLibrary from yombo.core.log import get_logger logger = get_logger("library.startup") class Startup(YomboLibrary): """ Start-up checks Checks to make sure basic configurations are valid and other start-up operations. """ # @inlineCallbacks def _init_(self,): if self._Loader.operation_mode != None: # will know if firstrun already or yombo.ini is missing. return need_config = False gwuuid = self._Configs.get("core", "gwuuid", None)
:copyright: 2013 Yombo :license: Yombo RPL 1.5 """ import time from collections import namedtuple from twisted.internet import reactor from yombo.core.helpers import getConfigValue from yombo.core.log import get_logger from yombo.core.module import YomboModule from yombo.lib.loader import getTheLoadedComponents # Don't use this! from yombo.utils.sqldict import SQLDict logger = get_logger("module.test") class ModuleUnitTest(YomboModule): """ ModuleUnitTest """ def _init_(self): """ Init the module. Don't use __init__ as that will override the setup functions of the base YomboModule class. Startup phase 1 of 3. """ self._ModDescription = "Insteon API command interface" self._ModAuthor = "Mitch Schwenk @ Yombo" self._ModUrl = "http://www.yombo.net"
from zope.interface import implementer # ----------- # Own modules # ----------- from .interfaces import IMQTTSubscriber from .base import ConnectedState as BaseConnectedState from .pubsubs import MQTTProtocol as PubSubsMQTTProtocol # Yombo Modules from yombo.core.log import get_logger log = get_logger('ext.mqttsubscriber') # --------------------------------- # MQTT Client Connected State Class # --------------------------------- class ConnectedState(BaseConnectedState): def subscribe(self, request): return self.protocol.doSubscribe(request) def unsubscribe(self, request): return self.protocol.doUnsubscribe(request) def handleSUBACK(self, response):
""" A simple module to test and demonstrate various automation hooks. This module also creates a few rules for demonstration. :copyright: 2016 Yombo :license: MIT """ from twisted.internet import reactor from yombo.core.log import get_logger from yombo.core.module import YomboModule logger = get_logger("modules.automationexample") class AutomationExample(YomboModule): """ This module adds a couple rules and toggles """ def _init_(self): logger.info("Output from translation: {out}", out=_('automationexample','demo.automationexample')) # demo of using i18n... self._ModDescription = "Demonstrates adding automation rules using a module." self._ModAuthor = "Mitch Schwenk @ Yombo" self._ModUrl = "https://yombo.net" # self._States['automationexample'] = 0 def _load_(self): # in 3 seconds from now, change the state - test the trigger # reactor.callLater(3, self.set_low)
# from signal import signal, SIGINT # Import twisted libraries from twisted.internet.defer import inlineCallbacks, maybeDeferred, returnValue, Deferred from twisted.internet import reactor from twisted.web import client client._HTTP11ClientFactory.noisy = False # Import Yombo libraries from yombo.core.exceptions import YomboCritical, YomboWarning, YomboNoSuchLoadedComponentError, YomboHookStopProcessing from yombo.utils.fuzzysearch import FuzzySearch from yombo.core.library import YomboLibrary from yombo.core.log import get_logger import yombo.utils logger = get_logger('library.loader') HARD_LOAD = OrderedDict() HARD_LOAD["Notifications"] = {'operation_mode':'all'} HARD_LOAD["LocalDB"] = {'operation_mode':'all'} HARD_LOAD["SQLDict"] = {'operation_mode':'all'} HARD_LOAD["Atoms"] = {'operation_mode':'all'} HARD_LOAD["States"] = {'operation_mode':'all'} HARD_LOAD["Configuration"] = {'operation_mode':'all'} HARD_LOAD["Statistics"] = {'operation_mode':'all'} HARD_LOAD["Startup"] = {'operation_mode':'all'} HARD_LOAD["AMQP"] = {'operation_mode':'run'} HARD_LOAD["YomboAPI"] = {'operation_mode':'all'} HARD_LOAD["GPG"] = {'operation_mode':'all'} HARD_LOAD["Automation"] = {'operation_mode':'all'} HARD_LOAD["CronTab"] = {'operation_mode':'all'}
from twisted.internet.defer import inlineCallbacks from twisted.internet.task import LoopingCall # Import Yombo libraries from yombo.core.entity import Entity from yombo.core.exceptions import YomboWarning, YomboHookStopProcessing from yombo.core.library import YomboLibrary from yombo.core.log import get_logger from yombo.mixins.library_db_child_mixin import LibraryDBChildMixin from yombo.mixins.sync_to_everywhere_mixin import SyncToEverywhereMixin from yombo.mixins.library_db_model_mixin import LibraryDBModelMixin from yombo.mixins.library_search_mixin import LibrarySearchMixin from yombo.utils import random_string, is_true_false from yombo.utils.hookinvoke import global_invoke_all logger = get_logger("library.notifications") class SlicableOrderedDict(OrderedDict): """ Allows an ordereddict to be called with: thisdict[1:2] Source: http://stackoverflow.com/questions/30975339/slicing-a-python-ordereddict Author: http://stackoverflow.com/users/1307905/anthon and Source: http://stackoverflow.com/questions/16664874/how-can-i-add-an-element-at-the-top-of-an-ordereddict-in-python Author: http://stackoverflow.com/users/846892/ashwini-chaudhary """ def __getitem__(self, k):
""" Color util methods. This file comes from the home assistant and has an Apache 2.0 license. This file has been modified to work with Yombo. """ import logging import math import colorsys from typing import Tuple from yombo.core.log import get_logger logger = get_logger("utils.color") # Official CSS3 colors from w3.org: # https://www.w3.org/TR/2010/PR-css3-color-20101028/#html4 # names do not have spaces in them so that we can compare against # reuqests more easily (by removing spaces from the requests as well). # This lets "dark seagreen" and "dark sea green" both match the same # color "darkseagreen". COLORS = { 'aliceblue': (240, 248, 255), 'antiquewhite': (250, 235, 215), 'aqua': (0, 255, 255), 'aquamarine': (127, 255, 212), 'azure': (240, 255, 255), 'beige': (245, 245, 220), 'bisque': (255, 228, 196), 'black': (0, 0, 0), 'blanchedalmond': (255, 235, 205),
.. moduleauthor:: Mitch Schwenk <*****@*****.**> :copyright: Copyright 2016 by Yombo. :license: LICENSE for details. """ from time import time # Import python libraries from functools import wraps # Import Yombo libraries from yombo.core.log import get_logger import yombo.utils logger = get_logger("utils.utils") def memoize_(func): """ Reuse the results of a static function. Subsequent calls will get cached results. **Usage**: .. code-block:: python from yombo.utils.decorators import memoize_ print fib(35) # Without decorator, will take a little bit of time. print fib(35) # With decorator, will be nearly instant - even on first call for a fib.
:copyright: Copyright 2016 by Yombo. :license: LICENSE for details. """ import operator # Import python libraries from time import time # Import Yombo libraries from yombo.core.exceptions import YomboWarning from yombo.core.module import YomboModule from yombo.core.log import get_logger from yombo.utils import is_string_bool, epoch_from_string logger = get_logger("library.automationhelper") # A list of possible operations that can be used in "basic_values" filters. ops = { "==": operator.eq, "!=": operator.ne, "<": operator.lt, "<=": operator.le, ">=": operator.ge, ">": operator.gt, "eq": operator.eq, "ne": operator.ne, "lt": operator.lt, "le": operator.le, "ge": operator.ge, "gt": operator.gt,
.. moduleauthor:: Mitch Schwenk <*****@*****.**> :copyright: Copyright 2012-2016 by Yombo. :license: LICENSE for details. """ from inspect import isclass import re from yombo.core.exceptions import YomboWarning from yombo.core.library import YomboLibrary from yombo.core.log import get_logger from yombo.utils import global_invoke_all, random_string from yombo.utils.fuzzysearch import FuzzySearch logger = get_logger('library.voice_cmds') class VoiceCmds(YomboLibrary): """ Store all voice commands here and perfrom searches. The purpose of this class is two fold: it provides a single repository for all possible noun/verb combinations, and provides an ability to *not* have to be 100% accurate when looking up noun/verb pairs. Convert "voice_cmd" strings into voice commands. Also, provides searching for voice commands. """ def __getitem__(self, voice_command_requested): """
import sys import traceback # Import twisted libraries from twisted.internet.defer import inlineCallbacks from twisted.internet import ssl, protocol, defer from twisted.internet import reactor # Import Yombo libraries from yombo.core.exceptions import YomboWarning from yombo.core.library import YomboLibrary from yombo.core.log import get_logger from yombo.utils import random_string from yombo.utils.maxdict import MaxDict logger = get_logger('library.amqp') class AMQP(YomboLibrary): """ This library can connect to any AMQP compatible server. It uses the Pika library to perform the actual AMQP handling. Developers should only be interested in the **new** function of this class. You will get back a :py:class:AMQPClient instance. This instance will allow you to subscribe, publish, and setup exchanges and queues. """ def _init_(self): self.client_connections = {} def _unload_(self):
# Import 3rd party extensions import yombo.ext.six as six # Import Yombo libraries from yombo.core.exceptions import YomboWarning from yombo.core.library import YomboLibrary from yombo.core.log import get_logger from yombo.utils import percentage, random_string import yombo.ext.umsgpack as msgpack # Handlers for processing various messages. from yombo.lib.handlers.amqpcontrol import AmqpControlHandler from yombo.lib.handlers.amqpconfigs import AmqpConfigHandler logger = get_logger('library.amqpyombo') PROTOCOL_VERSION = 3 # Which version of the yombo protocol we have implemented. PREFETCH_COUNT = 5 # Determine how many messages should be received/inflight before yombo servers # stop sending us messages. Should ACK/NACK all messages quickly. class AMQPYombo(YomboLibrary): """ Handles interactions with Yombo servers through the AMQP library. """ def _init_(self): """ Loads various variables and calls :py:meth:connect() when it's ready.
# Import python libraries from datetime import datetime, timedelta # Import twisted libraries from twisted.internet.task import LoopingCall from twisted.internet import reactor # Import Yombo libraries from yombo.utils import random_string from yombo.utils.fuzzysearch import FuzzySearch from yombo.core.exceptions import YomboFuzzySearchError, YomboCronTabError, YomboWarning from yombo.core.library import YomboLibrary from yombo.core.log import get_logger logger = get_logger('library.crontab') # Some utility classes / functions first class AllMatch(set): """Universal set - match everything""" def __contains__(self, item): return True allMatch = AllMatch() def conv_to_set(obj): # Allow single integer to be provided if isinstance(obj, str) and obj == '*': # return AllMatch return conv_to_set(AllMatch) if isinstance(obj, (int,long)): return set([obj]) # Single item if not isinstance(obj, set): obj = set(obj)
# ---------------- # Twisted modules # ---------------- # ----------- # Own modules # ----------- from . import PY2, v31, v311 from .error import StringValueError, PayloadValueError, PayloadTypeError # Yombo Modules from yombo.core.log import get_logger log = get_logger('ext.mqtt.pdu') # --------------------------------------- # MQTT Encoding/Decoding Helper functions # --------------------------------------- def encodeString(string): ''' Encode an UTF-8 string into MQTT format. Returns a bytearray ''' encoded = bytearray(2) encoded.extend(bytearray(string, encoding='utf-8')) l = len(encoded)-2 if(l > 65535): raise StringValueError(l)
# Import python libraries import codecs import ntpath import os # Import twisted libraries from twisted.internet import threads from twisted.internet.task import LoopingCall from twisted.internet.defer import inlineCallbacks from twisted.internet.reactor import callLater # Import Yombo libraries from yombo.core.exceptions import YomboWarning from yombo.core.log import get_logger logger = get_logger("utils.filewriter") class FileWriter: """ The file writer will open and keep a file open for writing. Typically used for log files. """ def __init__(self, filename, **kwargs): """ Generate a new File Writer instance. The params defined refer to kwargs and become class variables. The mode can be specified as well, the default mode is "a" for "append". You can use 2 write modes:
import json from hashlib import md5 from time import gmtime, strftime from os.path import abspath import __builtin__ import sys import traceback # Import 3rd-party libs import yombo.ext.polib as polib # Import Yombo libraries from yombo.core.library import YomboLibrary from yombo.core.log import get_logger logger = get_logger("library.localize") class Localize(YomboLibrary): """ Provides internaltionalization and localization where possible. Default language is 'en' (English). System and debug messages are never translated. """ def _init_(self): self.MSGCTXT_GLUE = "\004" temp = self._Configs.get('localize', 'hashes') self.default_lang = self._Configs.get('localize', 'default_lang', None, False) if temp is None: self.hashes = {'en':None} else: self.hashes = json.loads(temp)
# Import python libraries import re # Import twisted libraries from twisted.internet.defer import inlineCallbacks # Import Yombo libraries from yombo.core.exceptions import YomboWarning from yombo.core.log import get_logger # Import 3rd-party libs from yombo.utils import is_yes_no from yombo.utils.datatypes import coerce_value from yombo.utils.dictionaries import clean_dict logger = get_logger("library.localdb.storage") class DB_Storage(object): @inlineCallbacks def save_storage(self, storage): args = { "id": storage["id"], "scheme": storage["scheme"], "username": storage["username"], "password": storage["password"], "netloc": storage["netloc"], "port": storage["port"], "path": storage["path"], "params": storage["params"], "query": storage["query"], "fragment": storage["fragment"],
import json import time from yombo.core.module import YomboModule from yombo.core.log import get_logger logger = get_logger("modules.logwriter") class LogWriter(YomboModule): """ Simple log writer module - save yombo messages to log file. :author: U{Mitch Schwenk<*****@*****.**>} :organization: U{Automated Home Exchange (AHX)<http://www.ahx.me>} :copyright: 2010-2016 Yombo :license: see LICENSE.TXT from Yombo Gateway Software distribution """ def _init_(self): self._ModDescription = "Writes message to a log file." self._ModAuthor = "Mitch Schwenk @ Yombo" self._ModUrl = "http://www.yombo.net" self._RegisterDistributions = ['all'] # Get a file name save data to.. if "logfile" in self._ModVariables: self.fileName = self._ModVariables["logfile"][0]['value'] else: logger.warn("No 'logfile' set for log writing, using default: 'logwriter.txt'") self.fileName = "logwriter.txt"
from yombo.lib.webinterface.routes.api_v1.generic_library_routes import route_api_v1_generic_library_routes from yombo.utils.hookinvoke import global_invoke_all # # from yombo.lib.webinterface.routes.api_v1.camera import route_api_v1_camera # # from yombo.lib.webinterface.routes.api_v1.events import route_api_v1_events # # from yombo.lib.webinterface.routes.api_v1.gateway import route_api_v1_gateway # # from yombo.lib.webinterface.routes.api_v1.module import route_api_v1_module # # from yombo.lib.webinterface.routes.api_v1.notification import route_api_v1_notification # from yombo.lib.webinterface.routes.api_v1.scenes import route_api_v1_scenes # from yombo.lib.webinterface.routes.api_v1.server import route_api_v1_server # # from yombo.lib.webinterface.routes.api_v1.statistics import route_api_v1_statistics # # from yombo.lib.webinterface.routes.api_v1.storage import route_api_v1_storage # # from yombo.lib.webinterface.routes.api_v1.web_logs import route_api_v1_web_logs logger = get_logger("library.webinterface.mixins.load_routes") class LoadRoutesMixin: """ Loads all the various routes into the Klein webapp. """ def add_routes(self, reference): """ Add additional routes. See any of the routes file to examples. :param reference: :return: """ reference(self.webapp)
# ReconnectingClientFactory is becoming obsolete # since applications now have ClientService and its retryPolicy parameter # See chapter "Getting Connected with Endpoints" in the Twisted manual from twisted.internet.protocol import ReconnectingClientFactory # ----------- # Own modules # ----------- from .. import __version__ from ..error import ProfileValueError # Yombo Items from yombo.core.log import get_logger log = get_logger('ext.mqtt.factory') class MQTTFactory(ReconnectingClientFactory): SUBSCRIBER = 0x1 PUBLISHER = 0x2 def __init__(self, profile): self.profile = profile self.initialDelay = 0.8 # Some of these settings copied from yombo amqp self.jitter = 0.2 self.factor = 1.82 self.maxDelay = 25 # This equals to a max retry around 17-26 seconds # Packet Id generator self.id = 0 self.queuePublishTx = {
from slugify import slugify from socket import _GLOBAL_DEFAULT_TIMEOUT from typing import Any, Union, TypeVar, Callable, Sequence, Dict from urllib.parse import urlparse import voluptuous as vol # Import Yombo libraries from yombo.core.exceptions import YomboInvalidValidation, YomboWarning from yombo.core.library import YomboLibrary from yombo.core.log import get_logger from yombo.constants import \ TEMP_FAHRENHEIT, TEMP_CELSIUS, MISC_UNIT_SYSTEM_METRIC, MISC_UNIT_SYSTEM_IMPERIAL, WEEKDAYS from yombo.lib.template import JinjaTemplate import yombo.utils.datetime as dt logger = get_logger("library.validate") # typing typevar T = TypeVar("T") TIME_PERIOD_ERROR = "offset {} should be format 'HH:MM' or 'HH:MM:SS'" RE_SANITIZE_FILENAME = re.compile(r"(~|\.\.|/|\\)") RE_SANITIZE_PATH = re.compile(r"(~|\.(\.)+)") class Validate(YomboLibrary): """ Handles common validation tasks. """ #####################################################
from hashlib import sha256 import jwt from jwt.exceptions import PyJWTError, DecodeError, InvalidSignatureError, ExpiredSignatureError from time import time # Import twisted libraries from twisted.internet.defer import inlineCallbacks # Import Yombo libraries from yombo.classes.dictobject import DictObject from yombo.core.log import get_logger from yombo.lib.webinterface.auth import get_session import yombo.utils from yombo.utils.datatypes import coerce_value logger = get_logger("library.webinterface.routes.system_sso") def route_system_sso(webapp): with webapp.subroute("/system/sso") as webapp: @webapp.route("/user_auth", methods=["GET"]) @get_session() def page_system_sso_auth_get(webinterface, request, session): """ """ return webinterface.redirect(request, "/user/login") @webapp.route("/user_auth", methods=["POST"]) @get_session(create_session=True) @inlineCallbacks def page_system_sso_auth_post(webinterface, request, session):
import json from collections import deque from time import time import urllib # Import twisted libraries from twisted.internet.defer import inlineCallbacks, Deferred, returnValue from twisted.internet.task import LoopingCall # Import Yombo libraries from yombo.core.exceptions import YomboStateNotFound, YomboWarning, YomboHookStopProcessing from yombo.core.log import get_logger from yombo.core.library import YomboLibrary from yombo.utils import global_invoke_all, pattern_search, is_true_false, epoch_to_string, is_json, random_string logger = get_logger("library.YomboStates") class States(YomboLibrary, object): """ Provides a base API to store common states among libraries and modules. """ MAX_HISTORY = 100 def _init_(self): self._ModDescription = "Yombo States API" self._ModAuthor = "Mitch Schwenk @ Yombo" self._ModUrl = "https://yombo.net" self.automation = self._Libraries['automation'] self.__States = {} self._loaded = False
:copyright: Copyright 2019 by Yombo. :license: LICENSE for details. """ from time import time # Import twisted libraries from twisted.internet import reactor from twisted.internet.defer import inlineCallbacks # Import Yombo libraries from yombo.core.exceptions import YomboWarning from yombo.core.log import get_logger from yombo.utils import sleep logger = get_logger("mixins.sync_to_everywhere") SYNC_TO_DB = 1 SYNC_TO_YOMBO = 2 SYNC_TO_CONFIG = 4 CLASS_DEFAULTS = { "_sync_enabled": False, "_sync_delay": 5, "_sync_max_delay": 30, "_syncs_to_db": True, # If true, sync to db "_syncs_to_yombo": True, # If true, sync to yombo API. "_syncs_to_config": False, # If true, sync to yombo API. "_sync_init_complete": True, }
The FileReader also keeps track of where it left off between restarts so duplicate lines are not sent. It's smart enough to start at the top if the file is smaller than were it left off before. 2. Treats the incoming logfile as a stream of commands. This provides a simple method to allow other processes to trigger actions, such as "open garage door". :copyright: 2013-2016 Yombo :license: GPL """ from yombo.core.exceptions import YomboFileError from yombo.core.log import get_logger from yombo.core.module import YomboModule from yombo.utils.filereader import FileReader logger = get_logger("modules.logreader") class LogReader(YomboModule): """ Monitors a file for voice commands and send them to yombobot for processing. :ivar fileReader: A yombo :doc:`FileReader <../core/filereader>` that reads text files delivers lines of text to callable. """ def _init_(self): """ Init the module. """ self._ModDescription = "Logread monitors a file for voice commands." self._ModAuthor = "Mitch Schwenk @ Yombo"
""" from typing import Any, ClassVar, Dict, List, Optional # Import twisted libraries from twisted.internet.defer import inlineCallbacks # Import Yombo libraries from yombo.core.entity import Entity from yombo.core.library import YomboLibrary from yombo.core.log import get_logger from yombo.core.schemas import VariableFieldSchema from yombo.mixins.library_db_parent_mixin import LibraryDBParentMixin from yombo.mixins.library_search_mixin import LibrarySearchMixin from yombo.mixins.library_db_child_mixin import LibraryDBChildMixin logger = get_logger("library.variable_fields") class VariableField(Entity, LibraryDBChildMixin): """ A class to manage a single variable field item. """ _Entity_type: ClassVar[str] = "Variable field" _Entity_label_attribute: ClassVar[str] = "field_machine_label" @property def variable_group(self): try: return self._VariableGroups.group_by_id(self.variable_group_id) except KeyError: pass
# Import python libraries import gnupg import os from subprocess import Popen, PIPE # Import twisted libraries from twisted.internet.defer import inlineCallbacks, Deferred, returnValue # Import Yombo libraries from yombo.core.exceptions import YomboWarning from yombo.core.library import YomboLibrary from yombo.utils import random_string from yombo.core.log import get_logger logger = get_logger('library.gpg') class GPG(YomboLibrary): """ Manage all GPG functions. """ def _init_(self): """ Get the GnuPG subsystem up and loaded. """ self.gwid = self._Configs.get("core", "gwid") self.gwuuid = self._Configs.get("core", "gwuuid") self.mykeyid = self._Configs.get('gpg', 'keyid') self._key_generation_status = {}
from time import time from typing import Any, ClassVar, Dict, List, Optional, Type, Union # Import twisted libraries from twisted.internet.defer import inlineCallbacks # Import Yombo libraries from yombo.constants import VERSION from yombo.core.library import YomboLibrary from yombo.core.schemas import GatewaySchema from yombo.mixins.library_db_parent_mixin import LibraryDBParentMixin from yombo.mixins.library_search_mixin import LibrarySearchMixin from yombo.core.log import get_logger from yombo.lib.gateways.gateway import Gateway logger = get_logger("library.gateways") class Gateways(YomboLibrary, LibraryDBParentMixin, LibrarySearchMixin): """ Manages information about gateways. """ gateways = {} # The remaining attributes are used by various mixins. _storage_primary_field_name: ClassVar[str] = "gateway_id" _storage_attribute_name: ClassVar[str] = "gateways" _storage_label_name: ClassVar[str] = "gateway" _storage_class_reference: ClassVar = Gateway _storage_schema: ClassVar = GatewaySchema() _storage_search_fields: ClassVar[List[str]] = [
except ImportError: import json # Import twisted libraries from twisted.internet.defer import inlineCallbacks, Deferred, returnValue from twisted.web.client import Agent from twisted.internet import reactor import yombo.ext.treq as treq from yombo.ext.expiringdict import ExpiringDict # Import Yombo libraries from yombo.core.exceptions import YomboWarning, YomboWarningCredentails from yombo.core.library import YomboLibrary from yombo.core.log import get_logger logger = get_logger('library.yomboapi') class YomboAPI(YomboLibrary): contentType = None def _init_(self): self.custom_agent = Agent(reactor, connectTimeout=20) self.contentType = self._Configs.get('yomboapi', 'contenttype', 'application/json', False) # TODO: Msgpack later self.base_url = self._Configs.get('yomboapi', 'baseurl', "https://api.yombo.net/api", False) self.allow_system_session = self._Configs.get('yomboapi', 'allow_system_session', True) self.init_defer = None self.api_key = self._Configs.get('yomboapi', 'api_key', 'aBMKp5QcQoW43ipauw88R0PT2AohcE', False) self.valid_system_session = None self.session_validation_cache = ExpiringDict()
from typing import Any, ClassVar, Dict, List, Optional, Type, Union # Import twisted libraries from twisted.internet import threads from twisted.internet.defer import inlineCallbacks # Import Yombo libraries from yombo.core.exceptions import YomboWarning from yombo.core.library import YomboLibrary from yombo.core.log import get_logger # from yombo.mixins.library_search_mixin import LibrarySearchMixin # from yombo.mixins.parent_storage_accessors_mixin import ParentStorageAccessorsMixin # from yombo.mixins.child_storage_accessors_mixin import ChildStorageAccessorsMixin from yombo.utils import random_string, bytes_to_unicode, unicode_to_bytes logger = get_logger("library.encryption") class Encryption(YomboLibrary): """ Manage all encryption functions. """ @inlineCallbacks def _init_(self, **kwargs): """ Get the encryption system up - load the or create a default master key. """ aes_key_path = f"{self._working_dir}/etc/gpg/aes.key" try: self.__aes_key = yield self._Files.read(aes_key_path, convert_to_unicode=False)
import pika from typing import Callable, List, Optional, Union # Import twisted libraries from twisted.internet import reactor from twisted.internet import ssl # Import Yombo libraries from yombo.constants import VERSION from yombo.constants.amqp import KEEPALIVE, PREFETCH_COUNT from yombo.core.entity import Entity from yombo.core.exceptions import YomboWarning from yombo.core.log import get_logger from yombo.lib.amqp.amqpfactory import AMQPFactory logger = get_logger("library.amqp.amqpclient") class AMQPClient(Entity): def __init__( self, parent, client_id: str, hostname: str, port: int, virtual_host: str, username: str, password: str, use_ssl: bool, connected_callbacks: Optional[Union[Callable, List[Callable]]] = None,
# Import twisted libraries from twisted.internet.task import LoopingCall from twisted.internet.defer import inlineCallbacks, Deferred from twisted.internet import reactor # Import Yombo libraries from yombo.core.exceptions import YomboWarning from yombo.core.library import YomboLibrary from yombo.core.log import get_logger from yombo.utils import percentile, pattern_search, random_int, dict_merge from yombo.utils.decorators import cached from yombo.utils.hookinvoke import global_invoke_all from yombo.lib.statistics.buckets_manager import BucketsManager logger = get_logger("library.statistics") class Statistics(YomboLibrary): """ Library to process all the statistics. Allows long running data to be collectd on devices regardless of system actually running the devices. For example, can keep all history of a light bulb even when changing between X10, Insteon, or Z-Wave devices running the actual device. This also collections various system performance metrics. """ enabled = True # set to True to start, will be updated when configurations is loaded. count_bucket_duration = 300 # How many seconds averages_bucket_duration = 300 _counters = {} # stores counter information before it's saved to database _averages = {} # stores averages type information _datapoints = {} # stores datapoint data
""" from typing import Any, ClassVar, Dict, List, Optional, Type, Union # Import twisted libraries from twisted.internet.defer import inlineCallbacks # Import Yombo libraries from yombo.core.entity import Entity from yombo.core.library import YomboLibrary from yombo.core.log import get_logger from yombo.core.schemas import ModuleDeviceTypeSchema from yombo.mixins.library_db_child_mixin import LibraryDBChildMixin from yombo.mixins.library_db_parent_mixin import LibraryDBParentMixin from yombo.mixins.library_search_mixin import LibrarySearchMixin logger = get_logger("library.module_device_types") class ModuleDeviceType(Entity, LibraryDBChildMixin): """ A class to manage a single module device type. """ _Entity_type: ClassVar[str] = "Module device type" _Entity_label_attribute: ClassVar[str] = "module_device_type_id" class ModuleDeviceTypes(YomboLibrary, LibraryDBParentMixin, LibrarySearchMixin): """ Manages module device types. """
# Import twisted libraries from twisted.internet import threads from twisted.internet.defer import inlineCallbacks from twisted.internet.task import LoopingCall # Import Yombo libraries from yombo.ext.expiringdict import ExpiringDict from yombo.core.exceptions import YomboWarning from yombo.core.library import YomboLibrary from yombo.core.log import get_logger from yombo.utils import save_file, read_file, global_invoke_all, random_int, unicode_to_bytes, bytes_to_unicode from yombo.utils.dictobject import DictObject from .sslcert import SSLCert logger = get_logger('library.sslcerts') class SSLCerts(YomboLibrary): """ Responsible for managing various encryption and TLS (SSL) certificates. """ managed_certs = {} @inlineCallbacks def _init_(self, **kwargs): """ On startup, various libraries will need certs (webinterface, MQTT) for encryption. This module stores certificates in a directory so other programs can use certs as well. It's working data is stored in the database, while a backup is kept in the file system as well
This implements the state handling for /automation sub directory. .. moduleauthor:: Mitch Schwenk <*****@*****.**> .. versionadded:: 0.19.0 :copyright: Copyright 2018 by Yombo. :license: LICENSE for details. :view-source: `View Source Code <https://github.com/yombo/yombo-gateway/blob/master/yombo/lib/webinterface/routes/automation.py>`_ """ # Import Yombo libraries from yombo.lib.webinterface.auth import require_auth from yombo.core.exceptions import YomboWarning from yombo.core.log import get_logger from yombo.utils.datatypes import coerce_value logger = get_logger("library.webinterface.routes.automation.state") def route_automation_state(webapp): with webapp.subroute("/automation") as webapp: def root_breadcrumb(webinterface, request): webinterface.add_breadcrumb(request, "/", "Home") webinterface.add_breadcrumb(request, "/automation/index", "Automation") @webapp.route("/<string:rule_id>/set_trigger_state", methods=["GET"]) @require_auth() def page_automation_trigger_set_state_get(webinterface, request, session, rule_id): session.has_access("automation", rule_id, "edit", raise_error=True)
.. versionadded:: 0.20.0 :copyright: Copyright 2018 by Yombo. :license: LICENSE for details. """ from yombo.core.entity import Entity from yombo.constants import AUTH_TYPE_USER from yombo.core.log import get_logger from yombo.mixins.auth_mixin import AuthMixin from yombo.mixins.library_db_child_mixin import LibraryDBChildMixin from yombo.mixins.permission_mixin import PermissionMixin from yombo.mixins.roles_mixin import RolesMixin from yombo.mixins.sync_to_everywhere_mixin import SyncToEverywhereMixin from yombo.utils import data_pickle, data_unpickle logger = get_logger("library.users.user") class User(Entity, LibraryDBChildMixin, SyncToEverywhereMixin, AuthMixin, PermissionMixin, RolesMixin): """ User class to manage role membership, etc. """ _primary_column = "_user_id" # Used by mixins @property def user_id(self): return self._user_id @property def display(self):
:license: Yombo RPL 1.5 """ import time from collections import namedtuple # Import twisted libraries from twisted.internet import reactor from twisted.internet.defer import inlineCallbacks from twisted.internet.task import LoopingCall from yombo.core.log import get_logger from yombo.core.module import YomboModule from yombo.utils import sleep, bytes_to_unicode import yombo.utils.datetime as dt logger = get_logger("module.test") class ModuleUnitTest(YomboModule): """ ModuleUnitTest """ def _init_(self, **kwargs): """ """ # place to store our commands. self.available_commands = {} # store our devices self.devices = {}
from time import time import traceback from typing import Any, ClassVar, Dict, List, Optional, Type, Union # Import twisted libraries from twisted.internet import reactor from twisted.internet.defer import inlineCallbacks, maybeDeferred from twisted.internet.task import LoopingCall # Import Yombo libraries from yombo.core.library import YomboLibrary from yombo.core.exceptions import YomboWarning from yombo.core.log import get_logger from yombo.utils import random_int, random_string, sleep logger = get_logger("library.mqttyombo.atoms") class AtomsMixin: def incoming_atoms(self, source, destination, payload, **kwargs): """ Incoming atoms from various gateways. This sets global and cluster level atoms. :param payload: :param kwargs: :return: """ pass def send_atoms(self, destination=None,
# Import twisted libraries from twisted.internet import reactor from twisted.internet.defer import inlineCallbacks # Import Yombo libraries from yombo.constants.device_commands import * from yombo.core.entity import Entity from yombo.core.exceptions import YomboWarning from yombo.core.log import get_logger from yombo.mixins.library_db_child_mixin import LibraryDBChildMixin from yombo.utils import is_true_false from yombo.utils.caller import caller_string from yombo.utils.hookinvoke import global_invoke_all logger = get_logger("library.devices.device_commands.device_command") STATUS_TEXT = { DEVICE_COMMAND_STATUS_UNKNOWN: 0, DEVICE_COMMAND_STATUS_NEW: 100, DEVICE_COMMAND_STATUS_ACCEPTED: 200, DEVICE_COMMAND_STATUS_BROADCAST: 300, DEVICE_COMMAND_STATUS_SENT: 400, DEVICE_COMMAND_STATUS_RECEIVED: 500, DEVICE_COMMAND_STATUS_DELAYED: 600, DEVICE_COMMAND_STATUS_PENDING: 700, DEVICE_COMMAND_STATUS_DONE: 1000, DEVICE_COMMAND_STATUS_CANCELED: 2000, DEVICE_COMMAND_STATUS_FAILED: 2100, DEVICE_COMMAND_STATUS_EXPIRED: 2200, }
# Import 3rd-party libs import yombo.ext.six as six # Import twisted libraries from twisted.internet import reactor from twisted.internet.defer import inlineCallbacks, Deferred, returnValue # Import Yombo libraries from yombo.core.exceptions import YomboPinCodeError, YomboDeviceError, YomboFuzzySearchError, YomboWarning from yombo.utils.fuzzysearch import FuzzySearch from yombo.core.library import YomboLibrary from yombo.core.log import get_logger from yombo.utils import random_string, split, global_invoke_all, string_to_number from yombo.utils.maxdict import MaxDict from yombo.lib.commands import Command # used only to determine class type logger = get_logger('library.devices') class Variables(YomboLibrary): """ Various variable tools. """ def _init_(self): """ Setups up the basic framework. Nothing is loaded in here until the Load() stage. """ self.load_deferred = None # Prevents loader from moving on past _load_ until we are done. self._LocalDB = self._Libraries['localdb'] self.gwid = self._Configs.get("core", "gwid")
from time import time from twisted.internet.task import LoopingCall # Import twisted libraries from twisted.internet.defer import inlineCallbacks, returnValue, Deferred from twisted.internet import ssl, protocol, defer from twisted.internet import reactor # Import Yombo libraries from yombo.core.exceptions import YomboWarning from yombo.core.library import YomboLibrary from yombo.core.log import get_logger from yombo.utils import random_string import collections logger = get_logger('library.amqp') class AMQP(YomboLibrary): """ Base, or root class that manages all AMQP connections. """ def _init_(self, **kwargs): self.client_connections = {} self.messages_processed = None # Track incoming and outgoing messages. Meta data only. self.message_correlations = None # Track various bits of information for sent correlation_ids. self.init_deferred = Deferred() self.load_meta_data() return self.init_deferred
can receive the raw AMQP message, process it through AMQPYombo.incoming_raw, and then call either amqp_incoming_request or amqp_incoming_response depending on the message type. .. moduleauthor:: Mitch Schwenk <*****@*****.**> .. versionadded:: 0.24.0 :copyright: Copyright 2019-2020 by Yombo. :license: LICENSE for details. :view-source: `View Source Code <https://yombo.net/docs/gateway/html/current/_modules/yombo/mixins/amqp_mixin.html>`_ """ from twisted.internet.defer import inlineCallbacks, maybeDeferred from yombo.core.exceptions import YomboWarning from yombo.core.log import get_logger logger = get_logger("mixins.amqp_mixin") class AMQPMixin: @inlineCallbacks def amqp_incoming(self, channel, deliver, properties, message): """ Receives the raw AMQP message from the AMQP server. First, call 'AMQPYombo::incoming_raw' to validate and get something usable. Then, route the message to the proper handler. This callback is setup from the subscribe() method when the gateway is connected. :param channel: :param deliver: :param properties: :param message:
# Import python libraries from datetime import datetime, timedelta from difflib import SequenceMatcher import re # Import twisted libraries from twisted.internet.task import LoopingCall from twisted.internet.defer import inlineCallbacks, returnValue, Deferred # Import Yombo libraries from yombo.core.exceptions import YomboWarning from yombo.core.library import YomboLibrary from yombo.utils import percentile, global_invoke_all, pattern_search from yombo.core.log import get_logger logger = get_logger("library.statistics") class Statistics(YomboLibrary): """ Library to process all the statistics. Allows long running data to be collectd on devices regardless of system actually running the devices. For example, can keep all history of a light bulb even when changing between X10, Insteon, or Z-Wave devices running the actual device. This also collections various system performance metrics. """ enabled = True # set to True to start, will be updated when configurations is loaded. count_bucket_duration = 5 # How many minutes averages_bucket_duration = 5 _counters = {} # stores counter information before it's saved to database _averages = {} # stores averages type information
:copyright: Copyright 2017 by Yombo. :license: LICENSE for details. :view-source: `View Source Code <https://docs.yombo.net/gateway/html/current/_modules/yombo/lib/tasks.html>`_ """ from time import time # Import twisted libraries from twisted.enterprise import adbapi from twisted.internet.defer import inlineCallbacks, returnValue, Deferred from twisted.internet.task import LoopingCall # Import Yombo libraries from yombo.core.exceptions import YomboWarning from yombo.core.library import YomboLibrary from yombo.core.log import get_logger logger = get_logger('library.tasks') class Tasks(YomboLibrary): """ Performs various tasks at startup. """ def _init_(self, **kwargs): self.loop_tasks = {} self.init_deffered = Deferred() self.check_tasks('init', self.init_deffered) return self.init_deffered def _load_(self, **kwargs):
# ---------------- from zope.interface import implementer # ----------- # Own modules # ----------- from .interfaces import IMQTTPublisher from .base import IdleState, ConnectingState as BaseConnectingState, ConnectedState as BaseConnectedState from .pubsubs import MQTTProtocol as PubSubsMQTTProtocol # Yombo Modules from yombo.core.log import get_logger log = get_logger('ext.mqtt.publisher') # -------------------------------------------------- # MQTT Client Connecting State Class (for publisher) # -------------------------------------------------- class ConnectingState(BaseConnectingState): def handleCONNACK(self, response): self.protocol.handleCONNACK(response) # The standard allows publishing data without waiting for CONNACK def publish(self, request): return self.protocol.doPublish(request) # ---------------------------------
import re from time import time # Import twisted libraries from twisted.internet import threads from twisted.internet.defer import inlineCallbacks, Deferred from twisted.internet.task import LoopingCall # Import Yombo libraries from yombo.core.exceptions import YomboWarning, YomboCritical from yombo.core.library import YomboLibrary import yombo.core.settings as settings from yombo.utils import random_string, bytes_to_unicode, unicode_to_bytes, read_file, save_file, random_int from yombo.core.log import get_logger logger = get_logger("library.gpg") class GPG(YomboLibrary): """ Manage all GPG functions. """ @property def public_key(self): return self._gpg_keys[self.myfingerprint()]["publickey"] @public_key.setter def public_key(self, val): return @property
# ReconnectingClientFactory is becoming obsolete # since applications now have ClientService and its retryPolicy parameter # See chapter "Getting Connected with Endpoints" in the Twisted manual from twisted.internet.protocol import ReconnectingClientFactory # ----------- # Own modules # ----------- from .. import __version__ from ..error import ProfileValueError # Yombo Modules from yombo.core.log import get_logger log = get_logger('ext.mqtt.factory') class MQTTFactory(ReconnectingClientFactory): SUBSCRIBER = 0x1 PUBLISHER = 0x2 def __init__(self, profile): self.profile = profile self.factor = 2 self.maxDelay = 2*3600 # Packet Id generator self.id = 0 self.queuePublishTx = {} # PUBLISH messages waiting before being transmitted
import collections from functools import reduce from time import time # Import twisted libraries from twisted.internet.defer import inlineCallbacks # Import Yombo libraries from yombo.core.exceptions import YomboWarning from yombo.core.library import YomboLibrary from yombo.mixins.library_db_model_mixin import LibraryDBModelMixin from yombo.mixins.library_search_mixin import LibrarySearchMixin from yombo.core.log import get_logger from yombo.utils.hookinvoke import global_invoke_all logger = get_logger("library.inputtypes") BASE_INPUT_TYPE_PLATFORMS = { "yombo.lib.inputtypes.automation_addresses": ["X10_Address", "X10_House", "X10_Unit", "Insteon_Address"], "yombo.lib.inputtypes.basic_addresses": ["Email", "YomboUsername", "URI", "URL"], "yombo.lib.inputtypes.basic_types": [ "_Any", "_Bool", "_Checkbox", "_Float", "Filename", "_Integer", "_None", "Number", "Password", "Percent", "_String" ], "yombo.lib.inputtypes.ip_address": [ "IP_Address", "IP_Address_Public", "IP_Address_Private", "IPv4_Address", "IPv4_Address_Public", "IPv4_Address_Private", "IPv6_Address", "IPv6_Address_Public", "IPv6_Address_Private" ],
# Import 3rd-party libs from yombo.ext.twistar.registry import Registry from yombo.ext.twistar.utils import dictToWhere from yombo.ext.twistar.dbobject import DBObject # Import twisted libraries from twisted.enterprise import adbapi from twisted.internet.defer import inlineCallbacks, returnValue # Import Yombo libraries from yombo.core.library import YomboLibrary from yombo.core.log import get_logger from yombo.core.exceptions import YomboWarning from yombo.utils import clean_dict logger = get_logger('lib.sqlitedb') LATEST_SCHEMA_VERSION = 1 #### Various SQLite tables within the database. #### class Category(DBObject): TABLENAME='categories' class Command(DBObject): HABTM = [dict(name='device_types', join_table='CommandDeviceTypes')] pass class CommandDeviceTypes(DBObject): TABLENAME='command_device_types'
from yombo.lib.webinterface.routes.api_v1.states import route_api_v1_states from yombo.lib.webinterface.routes.api_v1.stream import broadcast as route_api_v1_stream_broadcast # from yombo.lib.webinterface.routes.api_v1.stream import route_api_v1_stream # from yombo.lib.webinterface.routes.api_v1.statistics import route_api_v1_statistics # from yombo.lib.webinterface.routes.api_v1.storage import route_api_v1_storage from yombo.lib.webinterface.routes.api_v1.system import route_api_v1_system from yombo.lib.webinterface.routes.api_v1.user import route_api_v1_user # from yombo.lib.webinterface.routes.api_v1.webinterface_logs import route_api_v1_webinterface_logs from yombo.lib.webinterface.routes.home import route_home from yombo.lib.webinterface.routes.misc import route_misc from yombo.lib.webinterface.routes.system import route_system from yombo.lib.webinterface.routes.user import route_user from yombo.lib.webinterface.constants import NAV_SIDE_MENU, DEFAULT_NODE, NOTIFICATION_PRIORITY_MAP_CSS logger = get_logger("library.webinterface") class WebInterface(YomboLibrary, BuildDistribution, ErrorHandler, Render, WebServer): """ Web interface framework. """ webapp = Klein() # Like Flask, but for twisted visits = 0 starting = True already_starting_web_servers = False hook_listeners = {} # special way to toss hook calls to routes. def _init_(self, **kwargs):
import struct import binascii #from twisted.internet.defer import inlineCallbacks, returnValue from twisted.internet.task import deferLater from twisted.internet import reactor # Import 3rd-party libs from yombo.core.exceptions import YomboWarning from yombo.utils.decorators import memoize_, memoize_ttl import yombo.ext.six as six from yombo.ext.hashids import Hashids from yombo.core.log import get_logger logger = get_logger('utils.__init__') # Import Yombo libraries from yombo.core.exceptions import YomboNoSuchLoadedComponentError, YomboWarning def pattern_search(look_for, items): """ Allows searching thru a list of items (a dict or list). For example, a list of: ['yombo.status.hello', 'yombo.status.bye', 'visitor.livingroom.hello'] You can search using #'s for whilecards consuming any number of spaces between or +'s as a wildcard for only on work. For example, a search of "#.hello" would result in:
from os import environ from string import Formatter import sys from time import time import traceback from typing import Any, ClassVar, Dict, List, Optional, Type, Union from twisted.internet.defer import inlineCallbacks # Import Yombo libraries from yombo.core.library import YomboLibrary from yombo.utils.converters import unit_convert from yombo.utils.dictionaries import recursive_dict_merge, access_dict from yombo.core.log import get_logger logger = get_logger("library.localize") class YomboFormatter(Formatter): """ Converts a localize string, applying arguments to it. """ def get_value(self, key, args, keywords): if isinstance(key, str): try: return keywords[key] except KeyError: return key else: return Formatter.get_value(key, args, keywords) class Localize(YomboLibrary):
from yombo.lib.webinterface.route_commands import route_commands from yombo.lib.webinterface.route_configs import route_configs from yombo.lib.webinterface.route_devices import route_devices from yombo.lib.webinterface.route_devtools import route_devtools from yombo.lib.webinterface.route_modules import route_modules from yombo.lib.webinterface.route_notices import route_notices from yombo.lib.webinterface.route_statistics import route_statistics from yombo.lib.webinterface.route_states import route_states from yombo.lib.webinterface.route_system import route_system from yombo.lib.webinterface.route_voicecmds import route_voicecmds from yombo.lib.webinterface.route_setup_wizard import route_setup_wizard #from yombo.lib.webinterfaceyombosession import YomboSession logger = get_logger("library.webconfig") simulate_gw = { 'new':{ 'label': '', 'description': '', 'variables': { 'elevation': '75', 'latitude': '37.758', 'longitude': '-122.438' } }, 'xyz1':{ 'label': 'Home', 'description': 'Main house gateway', 'variables': {
# Import python libraries from pika.spec import BasicProperties from pika.adapters import twisted_connection import sys import traceback from time import time from typing import Callable, List, Optional, Union # Import twisted libraries from twisted.internet.error import ConnectionDone from twisted.internet.defer import inlineCallbacks, maybeDeferred, DeferredList # Import Yombo libraries from yombo.core.log import get_logger logger = get_logger("library.amqp.amqpprotocol") class AMQPProtocol(twisted_connection.TwistedProtocolConnection): """ Responsible for low level handling. Does the actual work of setting up any exchanges, queues, and bindings. Also sends greeting and initial handshake. On connect, it always sends a message to let Yombo know of it's pertinent information. """ def __init__(self, factory): """ Save pointer to factory and then call it's parent __init__. """ self._channel = None self.do_send_types = {
except ImportError: import json from time import time # Import twisted libraries from twisted.internet.defer import inlineCallbacks, Deferred from twisted.internet.task import LoopingCall # Import Yombo libraries from yombo.ext.expiringdict import ExpiringDict from yombo.core.exceptions import YomboFuzzySearchError, YomboWarning from yombo.core.library import YomboLibrary from yombo.core.log import get_logger from yombo.utils import random_string logger = get_logger('library.logevents') class LogEvents(YomboLibrary): """ Manages all notifications. """ def _init_(self): """ Setups up the basic framework. """ # We only cache the last few events, and only for certain time. self.notifications = ExpiringDict(max_len=100, max_age_seconds=600) # return self.init_deferred def _load_(self):
:view-source: `View Source Code <https://yombo.net/docs/gateway/html/current/_modules/yombo/core/module.html>`_ """ import multiprocessing # Import twisted libraries from twisted.internet import reactor from twisted.application.service import Service from twisted.internet.defer import inlineCallbacks # Import Yombo libraries from yombo.lib.loader import setup_loader from yombo.core.log import get_logger from yombo.utils import set_twisted_logger as utils_logger from yombo.utils.decorators.deprecation import set_twisted_logger as utils_decorators_logger logger = get_logger("core.gwservice") class GWService(Service): """ Responsible for starting/stopping the entire Yombo Gateway service. This is called from Yombo.tac. """ loader = None def start(self): """ After twisted is running to get, call loader library and various starter functions to get everything started. """ # Threads are used for multiple items within the Yombo Gateway. They are used to prevent # blocking code. We need at least 40 threads to make things run smoothly.
import simplejson as json except ImportError: import json from time import time # Import twisted libraries from twisted.internet.defer import inlineCallbacks, Deferred from twisted.internet.task import LoopingCall # Import Yombo libraries from yombo.core.exceptions import YomboFuzzySearchError, YomboWarning from yombo.core.library import YomboLibrary from yombo.core.log import get_logger from yombo.utils import random_string logger = get_logger('library.notifications') class SlicableOrderedDict(OrderedDict): """ Allows an ordereddict to be called with: thisdict[1:2] Source: http://stackoverflow.com/questions/30975339/slicing-a-python-ordereddict Author: http://stackoverflow.com/users/1307905/anthon and Source: http://stackoverflow.com/questions/16664874/how-can-i-add-an-element-at-the-top-of-an-ordereddict-in-python Author: http://stackoverflow.com/users/846892/ashwini-chaudhary """ def __getitem__(self, k): if not isinstance(k, slice):
.. moduleauthor:: Mitch Schwenk <*****@*****.**> :copyright: Copyright 2012-2016 by Yombo. :license: LICENSE for details. """ # Import twisted libraries from twisted.internet import reactor from twisted.application.service import Service from twisted.internet.defer import inlineCallbacks # Import Yombo libraries from yombo.lib.loader import setup_loader from yombo.core.log import get_logger logger = get_logger('core.gwservice') class GWService(Service): """ Responsible for starting/stopping the entire Yombo Gateway service. This is called from Yombo.tac. """ loader = None def start(self): """ After twisted is running to get, call loader library and various starter functions to get everything started. """ reactor.callWhenRunning(self.start_loader_library) def startService(self):
""" # Import python libraries from hashlib import sha1 from time import time # Import 3rd-party libs import yombo.ext.hjson as hjson import yombo.ext.umsgpack as msgpack # Import Yombo libraries from yombo.core.exceptions import YomboAutomationWarning, YomboWarning from yombo.core.library import YomboLibrary from yombo.core.log import get_logger import yombo.utils logger = get_logger("library.automation") REQUIRED_RULE_FIELDS = ["trigger", "action", "name"] REQUIRED_TRIGGER_FIELDS = ["source"] REQUIRED_CONDITION_FIELDS = ["source", "filter"] REQUIRED_ACTION_FIELDS = ["platform"] REQUIRED_SOURCE_FIELDS = ["platform"] REQUIRED_FILTER_FIELDS = ["platform"] CONDITION_TYPE_AND = "and" CONDITION_TYPE_OR = "or" class Automation(YomboLibrary):
""" A starting point to creating your own module. This is a simple, nearly empty starter module. :copyright: 2012-2016 Yombo :license: GPL """ from twisted.internet import reactor from yombo.core.module import YomboModule from yombo.core.log import get_logger logger = get_logger("modules.empty") class Empty(YomboModule): """ This is an empty module used to bootstrap your own module. Simply copy/paste this directory to a new directory. Be sure to edit the __init__.py to match the new name. All methods (functions) defined below are optional. """ def _init_(self): """ Init the module. Don't use __init__ as that will override the setup functions of the base YomboModule class. Startup phase 1 of 3. .. literalinclude:: ../../../yombo/modules/empty/empty.py :language: python :lines: 20,33-35