本文整理汇总了Python中pytomation.devices.StateDevice.on方法的典型用法代码示例。如果您正苦于以下问题:Python StateDevice.on方法的具体用法?Python StateDevice.on怎么用?Python StateDevice.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pytomation.devices.StateDevice
的用法示例。
在下文中一共展示了StateDevice.on方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_trigger_time_range
# 需要导入模块: from pytomation.devices import StateDevice [as 别名]
# 或者: from pytomation.devices.StateDevice import on [as 别名]
def test_trigger_time_range(self):
(s_h, s_m, s_s) = datetime.now().timetuple()[3:6]
e_h = s_h
e_m = s_m
e_s = s_s + 2
s = StateDevice()
s2 = StateDevice(devices=s,
trigger={
Attribute.COMMAND: Command.ON,
Attribute.MAPPED: Command.OFF,
Attribute.SECS: 1,
Attribute.START: '{h}:{m}:{s}'.format(
h=s_h,
m=s_m,
s=s_s,
),
Attribute.END: '{h}:{m}:{s}'.format(
h=e_h,
m=e_m,
s=e_s,
),
},
)
self.assertEqual(s2.state, State.UNKNOWN)
s.on()
self.assertEqual(s2.state, State.ON)
time.sleep(3)
self.assertEqual(s2.state, State.OFF)
##
time.sleep(2)
s.on()
time.sleep(3)
self.assertEqual(s2.state, State.ON)
示例2: test_last_command
# 需要导入模块: from pytomation.devices import StateDevice [as 别名]
# 或者: from pytomation.devices.StateDevice import on [as 别名]
def test_last_command(self):
s1 = StateDevice()
s1.on()
self.assertEqual(s1.state, State.ON)
s1.off()
self.assertEqual(s1.state, State.OFF)
self.assertEqual(s1.last_command, Command.OFF)
示例3: test_delay_multiple
# 需要导入模块: from pytomation.devices import StateDevice [as 别名]
# 或者: from pytomation.devices.StateDevice import on [as 别名]
def test_delay_multiple(self):
d1 = StateDevice()
d2 = StateDevice()
d3 = StateDevice(
devices=(d1, d2),
delay=(
{Attribute.COMMAND: (Command.OFF),
Attribute.SOURCE: (d1),
Attribute.SECS: 2,
},
{Attribute.COMMAND: Command.OFF,
Attribute.SOURCE: d2,
Attribute.SECS: 4,
},
)
)
self.assertEqual(d3.state, State.UNKNOWN)
d3.on()
self.assertEqual(d3.state, State.ON)
d1.off()
self.assertEqual(d3.state, State.ON)
time.sleep(3)
self.assertEqual(d3.state, State.OFF)
#d2
d3.on()
self.assertEqual(d3.state, State.ON)
d2.off()
self.assertEqual(d3.state, State.ON)
time.sleep(3)
self.assertEqual(d3.state, State.ON)
time.sleep(1)
self.assertEqual(d3.state, State.OFF)
示例4: test_delay_zero_secs
# 需要导入模块: from pytomation.devices import StateDevice [as 别名]
# 或者: from pytomation.devices.StateDevice import on [as 别名]
def test_delay_zero_secs(self):
d1 = StateDevice()
d2 = StateDevice()
d3 = StateDevice(
devices=(d1, d2),
delay=({
Attribute.COMMAND: Command.OFF,
Attribute.SECS: 2
},
{
Attribute.COMMAND: Command.OFF,
Attribute.SECS: 0,
Attribute.SOURCE: d2,
}
),
initial=State.ON,
)
self.assertEqual(d3.state, State.ON)
d1.off()
self.assertEqual(d3.state, State.ON)
time.sleep(3)
self.assertEqual(d3.state, State.OFF)
d3.on()
self.assertEqual(d3.state, State.ON)
d2.off()
self.assertEqual(d3.state, State.OFF)
示例5: test_binding_default
# 需要导入模块: from pytomation.devices import StateDevice [as 别名]
# 或者: from pytomation.devices.StateDevice import on [as 别名]
def test_binding_default(self):
d1 = StateDevice()
d1.off()
d2 = StateDevice(d1)
self.assertEqual(d2.state, State.OFF)
d1.on()
self.assertEqual(d2.state, State.ON)
示例6: test_loop_prevention
# 需要导入模块: from pytomation.devices import StateDevice [as 别名]
# 或者: from pytomation.devices.StateDevice import on [as 别名]
def test_loop_prevention(self):
s1 = StateDevice()
s2 = StateDevice()
s1.devices(s2)
s2.devices(s1)
s1.on()
pass
示例7: test_time_off
# 需要导入模块: from pytomation.devices import StateDevice [as 别名]
# 或者: from pytomation.devices.StateDevice import on [as 别名]
def test_time_off(self):
now = datetime.now()
hours, mins, secs = now.timetuple()[3:6]
secs = (secs + 2) % 60
mins += (secs + 2) / 60
trigger_time1 = '{h}:{m}:{s}'.format(
h=hours,
m=mins,
s=secs,
)
print 'Trigger Time' + trigger_time1
secs = (secs + 2) % 60
mins += (secs + 2) / 60
trigger_time2 = '{h}:{m}:{s}'.format(
h=hours,
m=mins,
s=secs,
)
print 'Trigger Time' + trigger_time2
device = StateDevice(
time={
Attribute.COMMAND: Command.OFF,
Attribute.TIME: (trigger_time1, trigger_time2),
}
)
self.assertEqual(device.state, State.UNKNOWN)
time.sleep(3)
print datetime.now()
self.assertEqual(device.state, State.OFF)
device.on()
time.sleep(3)
print datetime.now()
print device._times
self.assertEqual(device.state, State.OFF)
示例8: test_state_ignore_range
# 需要导入模块: from pytomation.devices import StateDevice [as 别名]
# 或者: from pytomation.devices.StateDevice import on [as 别名]
def test_state_ignore_range(self):
(s_h, s_m, s_s) = datetime.now().timetuple()[3:6]
e_h = s_h
e_m = s_m
e_s = s_s + 2
s = StateDevice()
s2 = StateDevice(devices=s,
ignore={
Attribute.SOURCE: s,
Attribute.START: '{h}:{m}:{s}'.format(
h=s_h,
m=s_m,
s=s_s,
),
Attribute.END: '{h}:{m}:{s}'.format(
h=e_h,
m=e_m,
s=e_s,
),
},
)
self.assertEqual(s2.state, State.UNKNOWN)
s.on()
self.assertEqual(s2.state, State.UNKNOWN)
time.sleep(3)
s.on()
self.assertEqual(s2.state, State.ON)
示例9: test_trigger_out_range_gc
# 需要导入模块: from pytomation.devices import StateDevice [as 别名]
# 或者: from pytomation.devices.StateDevice import on [as 别名]
def test_trigger_out_range_gc(self):
(s_h, s_m, s_s) = datetime.now().timetuple()[3:6]
e_h = s_h
e_m = s_m
e_s = s_s + 2
d1 = StateDevice()
d2 = Light(
devices=d1,
trigger={
Attribute.COMMAND: Command.ON,
Attribute.MAPPED: Command.OFF,
Attribute.SECS: 2,
Attribute.START: '{h}:{m}:{s}'.format(
h=s_h,
m=s_m,
s=s_s,
),
Attribute.END: '{h}:{m}:{s}'.format(
h=e_h,
m=e_m,
s=e_s,
),
}
)
time.sleep(3)
self.assertEqual(d2.state, State.UNKNOWN)
d1.on()
self.assertEqual(d2.state, State.ON)
time.sleep(3)
self.assertEqual(d2.state, State.ON)
示例10: test_onStateChanged
# 需要导入模块: from pytomation.devices import StateDevice [as 别名]
# 或者: from pytomation.devices.StateDevice import on [as 别名]
def test_onStateChanged(self):
s1 = StateDevice()
custom = Mock()
s1.on()
s1.onStateChanged(custom.method)
s1.off()
custom.method.assert_called_with(State.OFF, source=None, prev=State.ON)
示例11: test_initial_from_device
# 需要导入模块: from pytomation.devices import StateDevice [as 别名]
# 或者: from pytomation.devices.StateDevice import on [as 别名]
def test_initial_from_device(self):
d1 = StateDevice(
)
self.assertEqual(d1.state, State.UNKNOWN)
d1.on()
self.assertEqual(d1.state, State.ON)
d2 = StateDevice(devices=d1)
self.assertEqual(d2.state, State.ON)
示例12: test_previous_state_command
# 需要导入模块: from pytomation.devices import StateDevice [as 别名]
# 或者: from pytomation.devices.StateDevice import on [as 别名]
def test_previous_state_command(self):
s1 = StateDevice()
s1.on()
self.assertEqual(s1.state, State.ON)
s1.off()
self.assertEqual(s1.state, State.OFF)
s1.previous()
self.assertEqual(s1.state, State.ON)
示例13: test_toggle_state
# 需要导入模块: from pytomation.devices import StateDevice [as 别名]
# 或者: from pytomation.devices.StateDevice import on [as 别名]
def test_toggle_state(self):
s1 = StateDevice()
s1.on()
self.assertEqual(s1.state, State.ON)
s1.toggle()
self.assertEqual(s1.state, State.OFF)
s1.toggle()
self.assertEqual(s1.state, State.ON)
示例14: test_bind_devices_initial_state
# 需要导入模块: from pytomation.devices import StateDevice [as 别名]
# 或者: from pytomation.devices.StateDevice import on [as 别名]
def test_bind_devices_initial_state(self):
s1 = StateDevice()
self.assertEqual(s1.state, State.UNKNOWN)
s1.on()
self.assertEqual(s1.state, State.ON)
s2 = StateDevice(s1)
self.assertEqual(s2.state, State.ON)
s3 = StateDevice(s1, initial_state=State.OFF)
self.assertEqual(s3.state, State.OFF)
示例15: test_override_default_maps
# 需要导入模块: from pytomation.devices import StateDevice [as 别名]
# 或者: from pytomation.devices.StateDevice import on [as 别名]
def test_override_default_maps(self):
d = StateDevice(
mapped={
Attribute.COMMAND: Command.ON,
Attribute.MAPPED: Command.OFF,
}
)
d.on()
self.assertEqual(d.state, State.OFF)