12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #!/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)
-
- # garden powerplugs
- self.garland_powerplug = pd.get(props.STG_ZGW, loc, roo, props.FUN_GAR)
- # repeater
- self.repeater = pd.get(props.STG_ZGW, loc, roo, props.FUN_REP)
-
- 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
- )
- # repeater
- self.repeater_videv = videv_switching(
- mqtt_client, config.TOPIC_GAR_GARDEN_REPEATER_VIDEV,
- self.repeater, self.repeater.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)
|