340 rivejä
15 KiB
Python

import config
import random
import report
import time
from mqtt import mqtt_client
from simulation.rooms import house
from .help import testSession
from .help import STATES_SW, STATES_BR, STATES_CT, STATES_TEMP
from tests.common_testcases import device_follow
def rand_tcel():
return random.choice(5 * [report.TCEL_FULL] + 3 * [report.TCEL_SHORT] + 2 * [report.TCEL_SMOKE])
def device_follow_sw(ts, master, slave, master_ch=0, slave_ch=0, single=False):
master_key = getattr(master, "KEY_OUTPUT_%d" % master_ch)
slave_key = getattr(slave, "KEY_OUTPUT_%d" % slave_ch)
#
master_name = master.get_name(master_key)
slave_name = slave.get_name(slave_key)
#
testcase_id = master_name + " -> " + slave_name
ts.testCase(
testcase_id, report.TCEL_SINGLE if single else rand_tcel(), device_follow,
master, master_key,
slave, slave_key,
STATES_SW, None
)
def device_follow_br(ts, master, slave, switch_on=None, single=False):
master_name = master.get_name(master.KEY_BRIGHTNESS)
slave_name = slave.get_name(slave.KEY_BRIGHTNESS)
#
testcase_id = master_name + " -> " + slave_name
ts.testCase(
testcase_id, report.TCEL_SINGLE if single else rand_tcel(), device_follow,
master, master.KEY_BRIGHTNESS,
slave, slave.KEY_BRIGHTNESS,
STATES_BR, switch_on
)
def device_follow_ct(ts, master, slave, switch_on=None, single=False):
master_name = master.get_name(master.KEY_COLOR_TEMP)
slave_name = slave.get_name(slave.KEY_COLOR_TEMP)
#
testcase_id = master_name + " -> " + slave_name
ts.testCase(
testcase_id, report.TCEL_SINGLE if single else rand_tcel(), device_follow,
master, master.KEY_COLOR_TEMP,
slave, slave.KEY_COLOR_TEMP,
STATES_CT, switch_on
)
def device_follow_temp(ts, master, slave, single=False):
master_name = master.get_name(master.KEY_USER_TEMPERATURE_SETPOINT)
slave_name = slave.get_name(slave.KEY_TEMPERATURE_SETPOINT)
#
testcase_id = master_name + " -> " + slave_name
ts.testCase(
testcase_id, report.TCEL_SINGLE if single else rand_tcel(), device_follow,
master, master.KEY_USER_TEMPERATURE_SETPOINT,
slave, slave.KEY_TEMPERATURE_SETPOINT,
STATES_TEMP, None
)
def preconditions(ts: testSession, mc: mqtt_client, h: house):
def precond_test(tLogger):
mc.send("videv/all/oof", True)
time.sleep(0.5)
tLogger.debug("Collecting precondition logs...")
# Clean-Up
ts.testCase('Clean-Up', report.TCEL_SINGLE, precond_test)
def ffe(ts: testSession, mc: mqtt_client, h: house):
#
# ffe.livingroom
#
room = h.ffe.livingroom
# Switching devices ##################################
# main_light videv<-->shelly
device_follow_sw(ts, room.videv_main_light, room.switch_main_light)
device_follow_sw(ts, room.switch_main_light, room.videv_main_light)
# floor_lamp videv<->zigbee + main_light->zigbee
device_follow_sw(ts, room.videv_floor_light, room.light_floor_light)
device_follow_sw(ts, room.light_floor_light, room.videv_floor_light)
device_follow_sw(ts, room.switch_main_light, room.light_floor_light)
# xmas_tree videv<-->shelly
if config.CHRISTMAS:
device_follow_sw(ts, room.videv_xmas_tree_light, room.switch_xmas_tree_light)
device_follow_sw(ts, room.switch_xmas_tree_light, room.videv_xmas_tree_light)
# Brightness and Colortemperature ####################
device_follow_br(ts, room.videv_main_light, room.light_main_light, room.switch_main_light)
device_follow_br(ts, room.light_main_light, room.videv_main_light, room.switch_main_light)
device_follow_ct(ts, room.videv_main_light, room.light_main_light, room.switch_main_light)
device_follow_ct(ts, room.light_main_light, room.videv_main_light, room.switch_main_light)
device_follow_br(ts, room.videv_floor_light, room.light_floor_light, room.light_floor_light)
device_follow_br(ts, room.light_floor_light, room.videv_floor_light, room.light_floor_light)
device_follow_ct(ts, room.videv_floor_light, room.light_floor_light, room.light_floor_light)
device_follow_ct(ts, room.light_floor_light, room.videv_floor_light, room.light_floor_light)
# Temperature ########################################
device_follow_temp(ts, room.videv_heating, room.valve_heating)
#
# ffe.sleep
#
room = h.ffe.sleep
# Switching devices ##################################
# main_light videv<-->shelly
device_follow_sw(ts, room.videv_main_light, room.switch_main_light)
device_follow_sw(ts, room.switch_main_light, room.videv_main_light)
# bed_light_di videv<-->zigbee
device_follow_sw(ts, room.videv_bed_dirk_light, room.light_bed_dirk_light)
device_follow_sw(ts, room.light_bed_dirk_light, room.videv_bed_dirk_light)
#
device_follow_sw(ts, room.videv_bed_marion_light, room.switch_bed_marion_light)
device_follow_sw(ts, room.switch_bed_marion_light, room.videv_bed_marion_light)
# Brightness and Colortemperature ####################
device_follow_br(ts, room.videv_main_light, room.light_main_light, room.switch_main_light)
device_follow_br(ts, room.light_main_light, room.videv_main_light, room.switch_main_light)
device_follow_ct(ts, room.videv_main_light, room.light_main_light, room.switch_main_light)
device_follow_ct(ts, room.light_main_light, room.videv_main_light, room.switch_main_light)
device_follow_br(ts, room.videv_bed_dirk_light, room.light_bed_dirk_light, room.light_bed_dirk_light)
device_follow_br(ts, room.light_bed_dirk_light, room.videv_bed_dirk_light, room.light_bed_dirk_light)
# TODO: Wardrobe
# Temperature ########################################
device_follow_temp(ts, room.videv_heating, room.valve_heating)
#
# ffe.diningroom
#
room = h.ffe.diningroom
# Switching devices ##################################
# main_light videv<-->shelly
device_follow_sw(ts, room.videv_main_light, room.switch_main_light)
device_follow_sw(ts, room.switch_main_light, room.videv_main_light)
# floor_lamp videv<->zigbee + main_light->zigbee
device_follow_sw(ts, room.videv_floor_light, room.switch_floor_light)
device_follow_sw(ts, room.switch_floor_light, room.videv_floor_light)
device_follow_sw(ts, room.switch_main_light, room.switch_floor_light)
# garland
if config.CHRISTMAS:
device_follow_sw(ts, room.videv_garland_light, room.switch_garland_light)
device_follow_sw(ts, room.switch_garland_light, room.videv_garland_light)
#
# ffe.kitchen
#
room = h.ffe.kitchen
# Switching devices ##################################
# main_light videv<-->shelly
device_follow_sw(ts, room.videv_main_light, room.switch_main_light)
device_follow_sw(ts, room.switch_main_light, room.videv_main_light)
# circulation_pump
device_follow_sw(ts, room.videv_circulation_pump, room.switch_circulation_pump)
device_follow_sw(ts, room.switch_circulation_pump, room.videv_circulation_pump)
# Brightness and Colortemperature ####################
# TODO: device_follow_br(ts, room.videv_main_light, room.light_main_light, room.switch_main_light)
# TODO: device_follow_br(ts, room.light_main_light, room.videv_main_light, room.switch_main_light)
# TODO: device_follow_ct(ts, room.videv_main_light, room.light_main_light, room.switch_main_light)
# TODO: device_follow_ct(ts, room.light_main_light, room.videv_main_light, room.switch_main_light)
# Temperature ########################################
device_follow_temp(ts, room.videv_heating, room.valve_heating)
#
# ffe.floor
#
# Switching devices ##################################
room = h.ffe.floor
# main_light videv<-->shelly
device_follow_sw(ts, room.videv_main_light, room.switch_main_light)
device_follow_sw(ts, room.switch_main_light, room.videv_main_light)
def ffw(ts: testSession, mc: mqtt_client, h: house):
#
# ffw.livingroom
#
room = h.ffw.livingroom
# Switching devices ##################################
# main_light videv<-->shelly
device_follow_sw(ts, room.videv_main_light, room.switch_main_light)
device_follow_sw(ts, room.switch_main_light, room.videv_main_light)
# Brightness and Colortemperature ####################
device_follow_br(ts, room.videv_main_light, room.light_main_light, room.switch_main_light)
device_follow_br(ts, room.light_main_light, room.videv_main_light, room.switch_main_light)
device_follow_ct(ts, room.videv_main_light, room.light_main_light, room.switch_main_light)
device_follow_ct(ts, room.light_main_light, room.videv_main_light, room.switch_main_light)
# Temperature ########################################
device_follow_temp(ts, room.videv_heating, room.valve_heating)
#
# ffw.sleep
#
room = h.ffw.sleep
# Switching devices ##################################
# main_light videv<-->shelly
device_follow_sw(ts, room.videv_main_light, room.switch_main_light)
device_follow_sw(ts, room.switch_main_light, room.videv_main_light)
# TODO: window_light
# Brightness and Colortemperature ####################
device_follow_br(ts, room.videv_main_light, room.light_main_light, room.switch_main_light)
device_follow_br(ts, room.light_main_light, room.videv_main_light, room.switch_main_light)
# Temperature ########################################
device_follow_temp(ts, room.videv_heating, room.valve_heating)
#
# ffw.julian
#
room = h.ffw.julian
# Switching devices ##################################
# main_light videv<-->shelly
device_follow_sw(ts, room.videv_main_light, room.switch_main_light)
device_follow_sw(ts, room.switch_main_light, room.videv_main_light)
# Brightness and Colortemperature ####################
device_follow_br(ts, room.videv_main_light, room.light_main_light, room.switch_main_light)
device_follow_br(ts, room.light_main_light, room.videv_main_light, room.switch_main_light)
device_follow_ct(ts, room.videv_main_light, room.light_main_light, room.switch_main_light)
device_follow_ct(ts, room.light_main_light, room.videv_main_light, room.switch_main_light)
# Temperature ########################################
device_follow_temp(ts, room.videv_heating, room.valve_heating)
#
# ffw.bath
#
room = h.ffw.bath
# Switching devices ##################################
# main_light videv<-->shelly
device_follow_sw(ts, room.videv_main_light, room.switch_main_light)
device_follow_sw(ts, room.switch_main_light, room.videv_main_light)
# Temperature ########################################
device_follow_temp(ts, room.videv_heating, room.valve_heating)
#
# ffw.floor
#
room = h.ffw.floor
# Switching devices ##################################
# main_light videv<-->shelly
device_follow_sw(ts, room.videv_main_light, room.switch_main_light)
device_follow_sw(ts, room.switch_main_light, room.videv_main_light)
def gfe(ts: testSession, mc: mqtt_client, h: house):
#
# gfe.
#
# room = h.gfe
# Switching devices ##################################
pass
def gfw(ts: testSession, mc: mqtt_client, h: house):
#
# gfw.dirk
#
room = h.gfw.dirk
# Switching devices ##################################
# main_light videv<-->shelly
device_follow_sw(ts, room.videv_main_light, room.switch_main_light)
device_follow_sw(ts, room.switch_main_light, room.videv_main_light)
# desk_light videv<-->tradfri
device_follow_sw(ts, room.videv_desk_light, room.light_desk_light)
device_follow_sw(ts, room.light_desk_light, room.videv_desk_light)
# desk_light videv<-->powerplug
device_follow_sw(ts, room.videv_pc_dock, room.switch_pc_dock)
device_follow_sw(ts, room.switch_pc_dock, room.videv_pc_dock)
# powerplug videv <-> channel
device_follow_sw(ts, room.videv_amplifier, room.switch_powerplug_4, slave_ch=0)
device_follow_sw(ts, room.switch_powerplug_4, room.videv_amplifier, master_ch=0)
device_follow_sw(ts, room.videv_phono, room.switch_powerplug_4, slave_ch=1)
device_follow_sw(ts, room.switch_powerplug_4, room.videv_phono, master_ch=1)
device_follow_sw(ts, room.videv_cd_player, room.switch_powerplug_4, slave_ch=2)
device_follow_sw(ts, room.switch_powerplug_4, room.videv_cd_player, master_ch=2)
device_follow_sw(ts, room.videv_bluetooth, room.switch_powerplug_4, slave_ch=3)
device_follow_sw(ts, room.switch_powerplug_4, room.videv_bluetooth, master_ch=3)
# powerplug follow
device_follow_sw(ts, room.switch_powerplug_4, room.switch_powerplug_4, master_ch=1, slave_ch=0)
device_follow_sw(ts, room.switch_powerplug_4, room.switch_powerplug_4, master_ch=2, slave_ch=0)
device_follow_sw(ts, room.switch_powerplug_4, room.switch_powerplug_4, master_ch=3, slave_ch=0)
# Brightness and Colortemperature ####################
device_follow_br(ts, room.videv_main_light, room.light_main_light, room.switch_main_light)
device_follow_br(ts, room.light_main_light, room.videv_main_light, room.switch_main_light)
device_follow_ct(ts, room.videv_main_light, room.light_main_light, room.switch_main_light)
device_follow_ct(ts, room.light_main_light, room.videv_main_light, room.switch_main_light)
device_follow_br(ts, room.videv_desk_light, room.light_desk_light, room.light_desk_light)
device_follow_br(ts, room.light_desk_light, room.videv_desk_light, room.light_desk_light)
device_follow_ct(ts, room.videv_desk_light, room.light_desk_light, room.light_desk_light)
device_follow_ct(ts, room.light_desk_light, room.videv_desk_light, room.light_desk_light)
# Temperature ########################################
device_follow_temp(ts, room.videv_heating, room.valve_heating)
#
# gfw.marion
#
room = h.gfw.marion
# Switching devices ##################################
# main_light videv<-->shelly
device_follow_sw(ts, room.videv_main_light, room.switch_main_light)
device_follow_sw(ts, room.switch_main_light, room.videv_main_light)
# floor_lamp videv<->zigbee + main_light->zigbee
device_follow_sw(ts, room.videv_window_light, room.light_window_light)
device_follow_sw(ts, room.light_window_light, room.videv_window_light)
device_follow_sw(ts, room.switch_main_light, room.light_window_light)
# Temperature ########################################
device_follow_temp(ts, room.videv_heating, room.valve_heating)
#
# gfw.floor
#
room = h.gfw.floor
# Switching devices ##################################
# main_light videv<-->shelly
device_follow_sw(ts, room.videv_main_light, room.switch_main_light)
device_follow_sw(ts, room.switch_main_light, room.videv_main_light)
# Brightness and Colortemperature ####################
device_follow_br(ts, room.videv_main_light, room.light_main_light, room.switch_main_light)
device_follow_br(ts, room.light_main_light, room.videv_main_light, room.switch_main_light)
device_follow_ct(ts, room.videv_main_light, room.light_main_light, room.switch_main_light)
device_follow_ct(ts, room.light_main_light, room.videv_main_light, room.switch_main_light)
def stw(ts: testSession, mc: mqtt_client, h: house):
#
# stairways
#
room = h.stairway
# Switching devices ##################################
# main_light videv<-->shelly
device_follow_sw(ts, room.videv_main_light, room.switch_main_light)
device_follow_sw(ts, room.switch_main_light, room.videv_main_light)