import voluptuous as vol from pi4home import pins import pi4home.config_validation as cv from pi4home.const import CONF_BUFFER_SIZE, CONF_DUMP, CONF_FILTER, CONF_ID, CONF_IDLE, \ CONF_PIN, CONF_TOLERANCE from pi4home.cpp_generator import Pvariable, add from pi4home.cpp_helpers import gpio_input_pin_expression, setup_component from pi4home.cpp_types import App, Component, pi4home_ns from pi4home.py_compat import string_types remote_ns = pi4home_ns.namespace('remote') MULTI_CONF = True RemoteControlComponentBase = remote_ns.class_('RemoteControlComponentBase') RemoteReceiverComponent = remote_ns.class_('RemoteReceiverComponent', RemoteControlComponentBase, Component) RemoteReceiveDumper = remote_ns.class_('RemoteReceiveDumper') DUMPERS = { 'jvc': remote_ns.class_('JVCDumper', RemoteReceiveDumper), 'lg': remote_ns.class_('LGDumper', RemoteReceiveDumper), 'nec': remote_ns.class_('NECDumper', RemoteReceiveDumper), 'panasonic': remote_ns.class_('PanasonicDumper', RemoteReceiveDumper), 'raw': remote_ns.class_('RawDumper', RemoteReceiveDumper), 'samsung': remote_ns.class_('SamsungDumper', RemoteReceiveDumper), 'sony': remote_ns.class_('SonyDumper', RemoteReceiveDumper), 'rc_switch': remote_ns.class_('RCSwitchDumper', RemoteReceiveDumper), 'rc5': remote_ns.class_('RC5Dumper', RemoteReceiveDumper),
import pi4home.config_validation as cv from pi4home.const import CONF_ALPHA, CONF_BLUE, CONF_BRIGHTNESS, CONF_COLORS, \ CONF_COLOR_TEMPERATURE, CONF_DEFAULT_TRANSITION_LENGTH, CONF_DURATION, CONF_EFFECT, \ CONF_EFFECTS, CONF_EFFECT_ID, CONF_FLASH_LENGTH, CONF_GAMMA_CORRECT, CONF_GREEN, CONF_ID, \ CONF_INTERNAL, CONF_LAMBDA, CONF_MQTT_ID, CONF_NAME, CONF_NUM_LEDS, CONF_RANDOM, CONF_RED, \ CONF_SPEED, CONF_STATE, CONF_TRANSITION_LENGTH, CONF_UPDATE_INTERVAL, CONF_WHITE, CONF_WIDTH from pi4home.core import CORE from pi4home.cpp_generator import Pvariable, StructInitializer, add, get_variable, process_lambda, \ templatable from pi4home.cpp_types import Action, Application, Component, Nameable, pi4home_ns, float_, \ std_string, uint32, void PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({}) # Base light_ns = pi4home_ns.namespace('light') LightState = light_ns.class_('LightState', Nameable, Component) # Fake class for addressable lights AddressableLightState = light_ns.class_('LightState', LightState) MakeLight = Application.struct('MakeLight') LightOutput = light_ns.class_('LightOutput') AddressableLight = light_ns.class_('AddressableLight') AddressableLightRef = AddressableLight.operator('ref') # Actions ToggleAction = light_ns.class_('ToggleAction', Action) TurnOffAction = light_ns.class_('TurnOffAction', Action) TurnOnAction = light_ns.class_('TurnOnAction', Action) LightColorValues = light_ns.class_('LightColorValues')
import voluptuous as vol 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)
import voluptuous as vol from pi4home.automation import ACTION_REGISTRY import pi4home.config_validation as cv from pi4home.const import CONF_ACCELERATION, CONF_DECELERATION, CONF_ID, CONF_MAX_SPEED, \ CONF_POSITION, CONF_TARGET from pi4home.core import CORE from pi4home.cpp_generator import Pvariable, add, get_variable, templatable from pi4home.cpp_types import Action, pi4home_ns, int32 PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({ }) # pylint: disable=invalid-name stepper_ns = pi4home_ns.namespace('stepper') Stepper = stepper_ns.class_('Stepper') SetTargetAction = stepper_ns.class_('SetTargetAction', Action) ReportPositionAction = stepper_ns.class_('ReportPositionAction', Action) def validate_acceleration(value): value = cv.string(value) for suffix in ('steps/s^2', 'steps/s*s', 'steps/s/s', 'steps/ss', 'steps/(s*s)'): if value.endswith(suffix): value = value[:-len(suffix)] if value == 'inf': return 1e6
}) BINARY_OUTPUT_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( BINARY_OUTPUT_SCHEMA.schema) FLOAT_OUTPUT_SCHEMA = BINARY_OUTPUT_SCHEMA.extend({ vol.Optional(CONF_MAX_POWER): cv.percentage, vol.Optional(CONF_MIN_POWER): cv.percentage, }) FLOAT_OUTPUT_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( FLOAT_OUTPUT_SCHEMA.schema) output_ns = pi4home_ns.namespace('output') BinaryOutput = output_ns.class_('BinaryOutput') BinaryOutputPtr = BinaryOutput.operator('ptr') FloatOutput = output_ns.class_('FloatOutput', BinaryOutput) FloatOutputPtr = FloatOutput.operator('ptr') # Actions TurnOffAction = output_ns.class_('TurnOffAction', Action) TurnOnAction = output_ns.class_('TurnOnAction', Action) SetLevelAction = output_ns.class_('SetLevelAction', Action) def setup_output_platform_(obj, config, skip_power_supply=False): if CONF_INVERTED in config: add(obj.set_inverted(config[CONF_INVERTED])) if not skip_power_supply and CONF_POWER_SUPPLY in config:
import voluptuous as vol from pi4home import automation from pi4home.automation import ACTION_REGISTRY, CONDITION_REGISTRY, Condition import pi4home.config_validation as cv from pi4home.const import CONF_DATA, CONF_DATA_TEMPLATE, CONF_ID, CONF_PASSWORD, CONF_PORT, \ CONF_REBOOT_TIMEOUT, CONF_SERVICE, CONF_VARIABLES, CONF_SERVICES, CONF_TRIGGER_ID from pi4home.core import CORE from pi4home.cpp_generator import Pvariable, add, get_variable, process_lambda from pi4home.cpp_helpers import setup_component from pi4home.cpp_types import Action, App, Component, StoringController, pi4home_ns, Trigger, \ bool_, int32, float_, std_string api_ns = pi4home_ns.namespace('api') APIServer = api_ns.class_('APIServer', Component, StoringController) HomeAssistantServiceCallAction = api_ns.class_('HomeAssistantServiceCallAction', Action) KeyValuePair = api_ns.class_('KeyValuePair') TemplatableKeyValuePair = api_ns.class_('TemplatableKeyValuePair') APIConnectedCondition = api_ns.class_('APIConnectedCondition', Condition) UserService = api_ns.class_('UserService', Trigger) ServiceTypeArgument = api_ns.class_('ServiceTypeArgument') ServiceArgType = api_ns.enum('ServiceArgType') SERVICE_ARG_TYPES = { 'bool': ServiceArgType.SERVICE_ARG_TYPE_BOOL, 'int': ServiceArgType.SERVICE_ARG_TYPE_INT, 'float': ServiceArgType.SERVICE_ARG_TYPE_FLOAT, 'string': ServiceArgType.SERVICE_ARG_TYPE_STRING, } SERVICE_ARG_NATIVE_TYPES = { 'bool': bool_,
from pi4home.automation import ACTION_REGISTRY, maybe_simple_id from pi4home.components import mqtt from pi4home.components.mqtt import setup_mqtt_component import pi4home.config_validation as cv from pi4home.const import CONF_ID, CONF_INTERNAL, CONF_MQTT_ID, CONF_OSCILLATING, \ CONF_OSCILLATION_COMMAND_TOPIC, CONF_OSCILLATION_STATE_TOPIC, CONF_SPEED, \ CONF_SPEED_COMMAND_TOPIC, CONF_SPEED_STATE_TOPIC from pi4home.core import CORE from pi4home.cpp_generator import Pvariable, add, get_variable, templatable from pi4home.cpp_types import Action, Application, Component, Nameable, bool_, pi4home_ns from pi4home.py_compat import string_types PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({}) fan_ns = pi4home_ns.namespace('fan') FanState = fan_ns.class_('FanState', Nameable, Component) MQTTFanComponent = fan_ns.class_('MQTTFanComponent', mqtt.MQTTComponent) MakeFan = Application.struct('MakeFan') # Actions TurnOnAction = fan_ns.class_('TurnOnAction', Action) TurnOffAction = fan_ns.class_('TurnOffAction', Action) ToggleAction = fan_ns.class_('ToggleAction', Action) FanSpeed = fan_ns.enum('FanSpeed') FAN_SPEED_OFF = FanSpeed.FAN_SPEED_OFF FAN_SPEED_LOW = FanSpeed.FAN_SPEED_LOW FAN_SPEED_MEDIUM = FanSpeed.FAN_SPEED_MEDIUM FAN_SPEED_HIGH = FanSpeed.FAN_SPEED_HIGH
CONF_STATE, CONF_TIMING, CONF_TRIGGER_ID, CONF_FOR from pi4home.core import CORE from pi4home.cpp_generator import Pvariable, StructInitializer, add, get_variable, process_lambda from pi4home.cpp_types import App, Component, Nameable, Trigger, bool_, pi4home_ns, optional from pi4home.py_compat import string_types DEVICE_CLASSES = [ '', '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_))
import voluptuous as vol from pi4home import automation from pi4home.components import mqtt from pi4home.components.mqtt import setup_mqtt_component import pi4home.config_validation as cv 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):
vol.Optional(CONF_QOS, default=0): cv.mqtt_qos, vol.Optional(CONF_RETAIN, default=True): cv.boolean, }) 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':')
import voluptuous as vol from pi4home.automation import ACTION_REGISTRY, maybe_simple_id from pi4home.components import mqtt from pi4home.components.mqtt import setup_mqtt_component import pi4home.config_validation as cv from pi4home.const import CONF_ID, CONF_INTERNAL, CONF_MQTT_ID from pi4home.core import CORE from pi4home.cpp_generator import Pvariable, add, get_variable from pi4home.cpp_types import Action, Nameable, pi4home_ns PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({ }) cover_ns = pi4home_ns.namespace('cover') Cover = cover_ns.class_('Cover', Nameable) MQTTCoverComponent = cover_ns.class_('MQTTCoverComponent', mqtt.MQTTComponent) CoverState = cover_ns.class_('CoverState') COVER_OPEN = cover_ns.COVER_OPEN COVER_CLOSED = cover_ns.COVER_CLOSED validate_cover_state = cv.one_of('OPEN', 'CLOSED', upper=True) COVER_STATES = { 'OPEN': COVER_OPEN, 'CLOSED': COVER_CLOSED, } # Actions
cv.positive_time_period_milliseconds, vol.Optional(CONF_DELTA): cv.float_, vol.Optional(CONF_UNIQUE): cv.invalid("The unique filter has been removed in 1.12, please " "replace with a delta filter with small value."), vol.Optional(CONF_HEARTBEAT): cv.positive_time_period_milliseconds, vol.Optional(CONF_DEBOUNCE): cv.positive_time_period_milliseconds, vol.Optional(CONF_OR): validate_recursive_filter, }, cv.has_exactly_one_key(*FILTER_KEYS)) # 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',
# coding=utf-8 import voluptuous as vol from pi4home import core from pi4home.automation import ACTION_REGISTRY, maybe_simple_id import pi4home.config_validation as cv from pi4home.const import CONF_LAMBDA, CONF_ROTATION, CONF_UPDATE_INTERVAL, CONF_PAGES, CONF_ID from pi4home.core import CORE from pi4home.cpp_generator import add, process_lambda, Pvariable, templatable, get_variable from pi4home.cpp_types import pi4home_ns, void, Action PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({ }) display_ns = pi4home_ns.namespace('display') DisplayBuffer = display_ns.class_('DisplayBuffer') DisplayPage = display_ns.class_('DisplayPage') DisplayPagePtr = DisplayPage.operator('ptr') DisplayBufferRef = DisplayBuffer.operator('ref') DisplayPageShowAction = display_ns.class_('DisplayPageShowAction', Action) DisplayPageShowNextAction = display_ns.class_('DisplayPageShowNextAction', Action) DisplayPageShowPrevAction = display_ns.class_('DisplayPageShowPrevAction', Action) DISPLAY_ROTATIONS = { 0: display_ns.DISPLAY_ROTATION_0_DEGREES, 90: display_ns.DISPLAY_ROTATION_90_DEGREES, 180: display_ns.DISPLAY_ROTATION_180_DEGREES, 270: display_ns.DISPLAY_ROTATION_270_DEGREES, }
import voluptuous as vol from pi4home import automation from pi4home.automation import ACTION_REGISTRY, CONDITION_REGISTRY, Condition, maybe_simple_id from pi4home.components import mqtt from pi4home.components.mqtt import setup_mqtt_component import pi4home.config_validation as cv from pi4home.const import CONF_ICON, CONF_ID, CONF_INTERNAL, CONF_INVERTED, CONF_MQTT_ID, \ CONF_ON_TURN_OFF, CONF_ON_TURN_ON, CONF_TRIGGER_ID from pi4home.core import CORE from pi4home.cpp_generator import Pvariable, add, get_variable from pi4home.cpp_types import Action, App, Nameable, Trigger, pi4home_ns 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())