smart_brain/function/garden.py

62 line
1.9 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import config
import devdi.topic as props
from function.helpers import day_event
from function.rooms import room, room_collection
from function.videv import videv_switching, videv_pure_switch
import logging
try:
from config import APP_NAME as ROOT_LOGGER_NAME
except ImportError:
ROOT_LOGGER_NAME = 'root'
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
loc = props.LOC_GAR
class garden(room_collection):
def __init__(self, mqtt_client, pd, vd):
super().__init__(mqtt_client, pd, vd)
self.garden = garden_garden(mqtt_client, pd, vd)
class garden_garden(room):
def __init__(self, mqtt_client, pd, vd):
roo = props.ROO_GAR
#
# Device initialisation
#
self.day_events = day_event((6, 0), (22, 0), 30, -30)
self.garland_powerplug = pd.get(props.STG_ZGW, loc, roo, props.FUN_GAR)
super().__init__(mqtt_client, pd, vd)
#
# Functionality initialisation
#
self.day_events.add_callback(None, True, self.__day_events__, True)
#
# Virtual Device Interface
#
# mode
self.mode_videv = videv_pure_switch(
mqtt_client, config.TOPIC_GAR_GARDEN_MODE_VIDEV
)
# garland
self.garland_videv = videv_switching(
mqtt_client, config.TOPIC_GAR_GARDEN_GARLAND_VIDEV,
self.garland_powerplug, self.garland_powerplug.KEY_OUTPUT_0
)
def __day_events__(self, device, key, data):
if self.mode_videv.get(self.mode_videv.KEY_STATE):
if key in (self.day_events.KEY_SUNSET, self.day_events.KEY_START_OF_DAY):
self.garland_powerplug.set_output_0(True)
elif key in (self.day_events.KEY_START_OF_NIGHT, self.day_events.KEY_SUNRISE):
self.garland_powerplug.set_output_0(False)