Exemple #1
0
from pi4home import automation
import pi4home.config_validation as cv
from pi4home.const import CONF_CRON, CONF_DAYS_OF_MONTH, CONF_DAYS_OF_WEEK, CONF_HOURS, \
    CONF_MINUTES, CONF_MONTHS, CONF_ON_TIME, CONF_SECONDS, CONF_TIMEZONE, CONF_TRIGGER_ID
from pi4home.core import CORE
from pi4home.cpp_generator import Pvariable, add
from pi4home.cpp_types import App, Component, Trigger, pi4home_ns
from pi4home.py_compat import string_types

_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({})

time_ns = pi4home_ns.namespace('time')
RealTimeClockComponent = time_ns.class_('RealTimeClockComponent', Component)
CronTrigger = time_ns.class_('CronTrigger', Trigger.template(), Component)
ESPTime = time_ns.struct('ESPTime')


def _tz_timedelta(td):
    offset_hour = int(td.total_seconds() / (60 * 60))
    offset_minute = int(abs(td.total_seconds() / 60)) % 60
    offset_second = int(abs(td.total_seconds())) % 60
    if offset_hour == 0 and offset_minute == 0 and offset_second == 0:
        return '0'
    if offset_minute == 0 and offset_second == 0:
        return '{}'.format(offset_hour)
    if offset_second == 0:
        return '{}:{}'.format(offset_hour, offset_minute)
    return '{}:{}:{}'.format(offset_hour, offset_minute, offset_second)
Exemple #2
0
from pi4home.components.spi import SPIComponent
import pi4home.config_validation as cv
from pi4home.const import CONF_CS_PIN, CONF_ID, CONF_ON_TAG, CONF_SPI_ID, CONF_TRIGGER_ID, \
    CONF_UPDATE_INTERVAL
from pi4home.cpp_generator import Pvariable, get_variable
from pi4home.cpp_helpers import gpio_output_pin_expression, setup_component
from pi4home.cpp_types import App, PollingComponent, Trigger, std_string

DEPENDENCIES = ['spi']
MULTI_CONF = True

PN532Component = binary_sensor.binary_sensor_ns.class_('PN532Component',
                                                       PollingComponent,
                                                       spi.SPIDevice)
PN532Trigger = binary_sensor.binary_sensor_ns.class_(
    'PN532Trigger', Trigger.template(std_string))

CONFIG_SCHEMA = cv.Schema({
    cv.GenerateID():
    cv.declare_variable_id(PN532Component),
    cv.GenerateID(CONF_SPI_ID):
    cv.use_variable_id(SPIComponent),
    vol.Required(CONF_CS_PIN):
    pins.gpio_output_pin_schema,
    vol.Optional(CONF_UPDATE_INTERVAL):
    cv.update_interval,
    vol.Optional(CONF_ON_TAG):
    automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID):
        cv.declare_variable_id(PN532Trigger),
    }),
Exemple #3
0
import voluptuous as vol

from pi4home import automation
import pi4home.config_validation as cv
from pi4home.const import CONF_ID, CONF_INTERVAL
from pi4home.cpp_generator import Pvariable
from pi4home.cpp_helpers import setup_component
from pi4home.cpp_types import App, PollingComponent, Trigger, pi4home_ns

IntervalTrigger = pi4home_ns.class_('IntervalTrigger', Trigger.template(),
                                    PollingComponent)

CONFIG_SCHEMA = automation.validate_automation(
    cv.Schema({
        cv.GenerateID():
        cv.declare_variable_id(IntervalTrigger),
        vol.Required(CONF_INTERVAL):
        cv.positive_time_period_milliseconds,
    }).extend(cv.COMPONENT_SCHEMA.schema))


def to_code(config):
    for conf in config:
        rhs = App.register_component(IntervalTrigger.new(conf[CONF_INTERVAL]))
        trigger = Pvariable(conf[CONF_ID], rhs)
        setup_component(trigger, conf)

        automation.build_automations(trigger, [], conf)
Exemple #4
0
from pi4home.const import CONF_ICON, CONF_ID, CONF_INTERNAL, CONF_MQTT_ID, CONF_ON_VALUE, \
    CONF_TRIGGER_ID
from pi4home.core import CORE
from pi4home.cpp_generator import Pvariable, add
from pi4home.cpp_types import App, Nameable, Trigger, pi4home_ns, std_string, Action

PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({})

# pylint: disable=invalid-name
text_sensor_ns = pi4home_ns.namespace('text_sensor')
TextSensor = text_sensor_ns.class_('TextSensor', Nameable)
TextSensorPtr = TextSensor.operator('ptr')
MQTTTextSensor = text_sensor_ns.class_('MQTTTextSensor', mqtt.MQTTComponent)

TextSensorStateTrigger = text_sensor_ns.class_('TextSensorStateTrigger',
                                               Trigger.template(std_string))
TextSensorPublishAction = text_sensor_ns.class_('TextSensorPublishAction',
                                                Action)

TEXT_SENSOR_SCHEMA = cv.MQTT_COMPONENT_SCHEMA.extend({
    cv.GenerateID(CONF_MQTT_ID):
    cv.declare_variable_id(MQTTTextSensor),
    vol.Optional(CONF_ICON):
    cv.icon,
    vol.Optional(CONF_ON_VALUE):
    automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID):
        cv.declare_variable_id(TextSensorStateTrigger),
    }),
})
Exemple #5
0
    '', 'battery', 'cold', 'connectivity', 'door', 'garage_door', 'gas',
    'heat', 'light', 'lock', 'moisture', 'motion', 'moving', 'occupancy',
    'opening', 'plug', 'power', 'presence', 'problem', 'safety', 'smoke',
    'sound', 'vibration', 'window'
]

PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({})

binary_sensor_ns = pi4home_ns.namespace('binary_sensor')
BinarySensor = binary_sensor_ns.class_('BinarySensor', Nameable)
BinarySensorPtr = BinarySensor.operator('ptr')
MQTTBinarySensorComponent = binary_sensor_ns.class_(
    'MQTTBinarySensorComponent', mqtt.MQTTComponent)

# Triggers
PressTrigger = binary_sensor_ns.class_('PressTrigger', Trigger.template())
ReleaseTrigger = binary_sensor_ns.class_('ReleaseTrigger', Trigger.template())
ClickTrigger = binary_sensor_ns.class_('ClickTrigger', Trigger.template())
DoubleClickTrigger = binary_sensor_ns.class_('DoubleClickTrigger',
                                             Trigger.template())
MultiClickTrigger = binary_sensor_ns.class_('MultiClickTrigger',
                                            Trigger.template(), Component)
MultiClickTriggerEvent = binary_sensor_ns.struct('MultiClickTriggerEvent')
StateTrigger = binary_sensor_ns.class_('StateTrigger', Trigger.template(bool_))

# Condition
BinarySensorCondition = binary_sensor_ns.class_('BinarySensorCondition',
                                                Condition)

# Filters
Filter = binary_sensor_ns.class_('Filter')
Exemple #6
0
MQTT_MESSAGE_TEMPLATE_SCHEMA = vol.Any(None, MQTT_MESSAGE_BASE,
                                       validate_message_just_topic)

MQTT_MESSAGE_SCHEMA = vol.Any(
    None,
    MQTT_MESSAGE_BASE.extend({
        vol.Required(CONF_PAYLOAD): cv.mqtt_payload,
    }))

mqtt_ns = pi4home_ns.namespace('mqtt')
MQTTMessage = mqtt_ns.struct('MQTTMessage')
MQTTClientComponent = mqtt_ns.class_('MQTTClientComponent', Component)
MQTTPublishAction = mqtt_ns.class_('MQTTPublishAction', Action)
MQTTPublishJsonAction = mqtt_ns.class_('MQTTPublishJsonAction', Action)
MQTTMessageTrigger = mqtt_ns.class_('MQTTMessageTrigger',
                                    Trigger.template(std_string))
MQTTJsonMessageTrigger = mqtt_ns.class_('MQTTJsonMessageTrigger',
                                        Trigger.template(JsonObjectConstRef))
MQTTComponent = mqtt_ns.class_('MQTTComponent', Component)
MQTTConnectedCondition = mqtt_ns.class_('MQTTConnectedCondition', Condition)


def validate_config(value):
    if CONF_PORT not in value:
        parts = value[CONF_BROKER].split(u':')
        if len(parts) == 2:
            value[CONF_BROKER] = parts[0]
            value[CONF_PORT] = cv.port(parts[1])
        else:
            value[CONF_PORT] = 1883
    return value
Exemple #7
0
# Base
sensor_ns = pi4home_ns.namespace('sensor')
Sensor = sensor_ns.class_('Sensor', Nameable)
SensorPtr = Sensor.operator('ptr')
MQTTSensorComponent = sensor_ns.class_('MQTTSensorComponent',
                                       mqtt.MQTTComponent)

PollingSensorComponent = sensor_ns.class_('PollingSensorComponent',
                                          PollingComponent, Sensor)
EmptySensor = sensor_ns.class_('EmptySensor', Sensor)
EmptyPollingParentSensor = sensor_ns.class_('EmptyPollingParentSensor',
                                            EmptySensor)

# Triggers
SensorStateTrigger = sensor_ns.class_('SensorStateTrigger',
                                      Trigger.template(float_))
SensorRawStateTrigger = sensor_ns.class_('SensorRawStateTrigger',
                                         Trigger.template(float_))
ValueRangeTrigger = sensor_ns.class_('ValueRangeTrigger',
                                     Trigger.template(float_), Component)

# Filters
Filter = sensor_ns.class_('Filter')
SlidingWindowMovingAverageFilter = sensor_ns.class_(
    'SlidingWindowMovingAverageFilter', Filter)
ExponentialMovingAverageFilter = sensor_ns.class_(
    'ExponentialMovingAverageFilter', Filter)
LambdaFilter = sensor_ns.class_('LambdaFilter', Filter)
OffsetFilter = sensor_ns.class_('OffsetFilter', Filter)
MultiplyFilter = sensor_ns.class_('MultiplyFilter', Filter)
FilterOutValueFilter = sensor_ns.class_('FilterOutValueFilter', Filter)
Exemple #8
0
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({})

switch_ns = pi4home_ns.namespace('switch_')
Switch = switch_ns.class_('Switch', Nameable)
SwitchPtr = Switch.operator('ptr')
MQTTSwitchComponent = switch_ns.class_('MQTTSwitchComponent',
                                       mqtt.MQTTComponent)

ToggleAction = switch_ns.class_('ToggleAction', Action)
TurnOffAction = switch_ns.class_('TurnOffAction', Action)
TurnOnAction = switch_ns.class_('TurnOnAction', Action)

SwitchCondition = switch_ns.class_('SwitchCondition', Condition)
SwitchTurnOnTrigger = switch_ns.class_('SwitchTurnOnTrigger',
                                       Trigger.template())
SwitchTurnOffTrigger = switch_ns.class_('SwitchTurnOffTrigger',
                                        Trigger.template())

SWITCH_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
    cv.GenerateID(CONF_MQTT_ID):
    cv.declare_variable_id(MQTTSwitchComponent),
    vol.Optional(CONF_ICON):
    cv.icon,
    vol.Optional(CONF_INVERTED):
    cv.boolean,
    vol.Optional(CONF_ON_TURN_ON):
    automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID):
        cv.declare_variable_id(SwitchTurnOnTrigger),
    }),