room_shelly_motion_sensor adapted to fit to silvercrest functionality
This commit is contained in:
parent
4e4a6a2a01
commit
6a7f17feff
@ -6,7 +6,7 @@ import config
|
|||||||
import devices
|
import devices
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from function.rooms import room_shelly, room_shelly_auto_off, room_shelly_tradfri_light
|
from function.rooms import room_shelly, room_shelly_motion_sensor, room_shelly_tradfri_light
|
||||||
from function.helpers import changed_value_indicator
|
from function.helpers import changed_value_indicator
|
||||||
try:
|
try:
|
||||||
from config import APP_NAME as ROOT_LOGGER_NAME
|
from config import APP_NAME as ROOT_LOGGER_NAME
|
||||||
@ -15,12 +15,10 @@ except ImportError:
|
|||||||
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
|
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
|
||||||
|
|
||||||
|
|
||||||
class first_floor_east_floor(room_shelly_auto_off):
|
class first_floor_east_floor(room_shelly_motion_sensor):
|
||||||
def __init__(self, mqtt_client):
|
def __init__(self, mqtt_client):
|
||||||
# http://shelly1l-3C6105E4E629
|
# http://shelly1l-3C6105E4E629
|
||||||
super().__init__(mqtt_client, "shellies/ffe/floor/main_light", "gui/ffe/floor/main_light/switch")
|
super().__init__(mqtt_client, "shellies/ffe/floor/main_light", "gui/ffe/floor/main_light/switch", "zigbee/ffe/floor/motion_sensor")
|
||||||
self.motion_sensor_silvercrest = devices.silvercrest_motion_sensor(mqtt_client, "zigbee/ffe/floor/motion_sensor")
|
|
||||||
self.motion_sensor_silvercrest.add_callback(devices.silvercrest_motion_sensor.KEY_OCCUPANCY, True, self.main_light_shelly.set_output_0_mcb)
|
|
||||||
|
|
||||||
|
|
||||||
class first_floor_east_kitchen(room_shelly):
|
class first_floor_east_kitchen(room_shelly):
|
||||||
|
@ -56,26 +56,46 @@ class room_shelly(room):
|
|||||||
self.last_flash_data = data
|
self.last_flash_data = data
|
||||||
|
|
||||||
|
|
||||||
class room_shelly_auto_off(room_shelly):
|
class room_shelly_motion_sensor(room_shelly):
|
||||||
def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, timer_value=30):
|
def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_motion_sensor_1, topic_motion_sensor_2=None, timer_value=30):
|
||||||
super().__init__(mqtt_client, topic_shelly, topic_gui_switch)
|
super().__init__(mqtt_client, topic_shelly, topic_gui_switch)
|
||||||
self.timer_value = timer_value
|
self.timer_value = timer_value
|
||||||
self.main_light_timer = None
|
|
||||||
#
|
#
|
||||||
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.reload_timer, True)
|
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.reload_timer, True)
|
||||||
#
|
#
|
||||||
|
self.motion_sensor_silvercrest_1 = devices.silvercrest_motion_sensor(mqtt_client, topic_motion_sensor_1)
|
||||||
|
self.motion_sensor_silvercrest_1.add_callback(devices.silvercrest_motion_sensor.KEY_OCCUPANCY, None, self.set_motion_detected)
|
||||||
|
#
|
||||||
|
if topic_motion_sensor_2 is not None:
|
||||||
|
self.motion_sensor_silvercrest_2 = devices.silvercrest_motion_sensor(mqtt_client, topic_motion_sensor_2)
|
||||||
|
self.motion_sensor_silvercrest_2.add_callback(devices.silvercrest_motion_sensor.KEY_OCCUPANCY, None, self.set_motion_detected)
|
||||||
|
#
|
||||||
|
self.motion_detected_1 = False
|
||||||
|
self.motion_detected_2 = False
|
||||||
|
self.main_light_timer = None
|
||||||
|
#
|
||||||
cyclic_task = task.periodic(1, self.cyclic_task)
|
cyclic_task = task.periodic(1, self.cyclic_task)
|
||||||
cyclic_task.run()
|
cyclic_task.run()
|
||||||
|
|
||||||
|
def set_motion_detected(self, device, key, data):
|
||||||
|
if device == self.motion_sensor_silvercrest_1:
|
||||||
|
self.motion_detected_1 = data
|
||||||
|
elif device == self.motion_sensor_silvercrest_2:
|
||||||
|
self.motion_detected_2 = data
|
||||||
|
if data is True:
|
||||||
|
self.main_light_shelly.set_output_0(True)
|
||||||
|
|
||||||
def reload_timer(self, device, key, data):
|
def reload_timer(self, device, key, data):
|
||||||
self.main_light_timer = self.timer_value
|
self.main_light_timer = self.timer_value
|
||||||
|
|
||||||
def cyclic_task(self, cyclic_task):
|
def cyclic_task(self, cyclic_task):
|
||||||
if self.main_light_timer is not None:
|
if self.main_light_timer is not None:
|
||||||
self.main_light_timer -= cyclic_task.cycle_time
|
|
||||||
if self.main_light_timer <= 0:
|
if self.main_light_timer <= 0:
|
||||||
self.main_light_shelly.set_output_0(False)
|
if not self.motion_detected_1 and not self.motion_detected_2:
|
||||||
self.main_light_timer = None
|
self.main_light_shelly.set_output_0(False)
|
||||||
|
self.main_light_timer = None
|
||||||
|
else:
|
||||||
|
self.main_light_timer -= cyclic_task.cycle_time
|
||||||
|
|
||||||
|
|
||||||
class room_shelly_tradfri_light(room_shelly):
|
class room_shelly_tradfri_light(room_shelly):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user