本文整理汇总了Python中openzwave.network.ZWaveNetwork.stop方法的典型用法代码示例。如果您正苦于以下问题:Python ZWaveNetwork.stop方法的具体用法?Python ZWaveNetwork.stop怎么用?Python ZWaveNetwork.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openzwave.network.ZWaveNetwork
的用法示例。
在下文中一共展示了ZWaveNetwork.stop方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestApi
# 需要导入模块: from openzwave.network import ZWaveNetwork [as 别名]
# 或者: from openzwave.network.ZWaveNetwork import stop [as 别名]
class TestApi(TestPyZWave):
"""
Parent test class for api
"""
@classmethod
def setUpClass(self):
super(TestApi, self).setUpClass()
self.options = ZWaveOption(device=self.device, user_path=self.userpath)
self.options.set_log_file("OZW_Log.log")
self.options.set_append_log_file(False)
self.options.set_console_output(False)
self.options.set_save_log_level("Debug")
self.options.set_logging(True)
self.options.lock()
self.ctrl_command_result = None
dispatcher.connect(self.ctrl_message, ZWaveController.SIGNAL_CONTROLLER)
self.node_result = None
dispatcher.connect(self.node_update, ZWaveNetwork.SIGNAL_NODE)
self.network = ZWaveNetwork(self.options)
time.sleep(1.0)
@classmethod
def tearDownClass(self):
self.network.stop()
time.sleep(2.0)
super(TestApi, self).tearDownClass()
self.network=None
def setUp(self):
self.wait_for_network_state(self.network.STATE_AWAKED, 1)
def wait_for_queue(self):
for i in range(0,60):
if self.network.controller.send_queue_count <= 0:
break
else:
time.sleep(0.5)
def wait_for_network_state(self, state, multiply=1):
for i in range(0,SLEEP*multiply):
if self.network.state>=state:
break
else:
#sys.stdout.write(".")
#sys.stdout.flush()
time.sleep(1.0)
def ctrl_message(self, state, message, network, controller):
self.ctrl_command_result = state
def node_update(self, network, node):
self.node_result = node
示例2: TestNetworkStartStop
# 需要导入模块: from openzwave.network import ZWaveNetwork [as 别名]
# 或者: from openzwave.network.ZWaveNetwork import stop [as 别名]
class TestNetworkStartStop(TestPyZWave):
@classmethod
def setUpClass(self):
super(TestNetworkStartStop, self).setUpClass()
self.options = None
self.network = None
@classmethod
def tearDownClass(self):
if self.network is not None:
self.network.stop()
super(TestNetworkStartStop, self).tearDownClass()
def test_000_network_start_stop(self):
self.driver_ready = False
self.driver_removed = False
self.options = ZWaveOption(device=self.device, user_path=self.userpath)
self.options.set_log_file("OZW_Log.log")
self.options.set_append_log_file(False)
self.options.set_console_output(False)
self.options.set_save_log_level("Debug")
self.options.set_logging(True)
self.options.lock()
dispatcher.connect(self.driver_ready_message, ZWaveNetwork.SIGNAL_DRIVER_READY)
dispatcher.connect(self.driver_removed_message, ZWaveNetwork.SIGNAL_DRIVER_REMOVED)
self.network = ZWaveNetwork(self.options)
for i in range(0, SLEEP):
if self.network.state>=self.network.STATE_AWAKED:
break
else:
time.sleep(1.0)
self.assertTrue(self.driver_ready)
self.network.stop()
for i in range(0, SLEEP):
if self.network.state==self.network.STATE_STOPPED:
break
else:
time.sleep(1.0)
self.assertEqual(self.network.state, self.network.STATE_STOPPED)
#self.assertTrue(self.driver_removed)
self.network = None
def driver_ready_message(self, network, controller):
self.driver_ready = True
def driver_removed_message(self, network):
self.driver_removed = True
示例3: main
# 需要导入模块: from openzwave.network import ZWaveNetwork [as 别名]
# 或者: from openzwave.network.ZWaveNetwork import stop [as 别名]
def main():
global LIGHT, PUSHOVER
logging.basicConfig(level=logging.INFO,
format="%(asctime)-15s %(levelno)d %(message)s")
# TODO: Put in argparse
device = None
if device is None:
device = discover_device()
check_device(device)
CONFIG = read_config("config.json")
if CONFIG.pushover.apikey is not None:
logging.info("Setting up Pushover")
PUSHOVER = Pushover(CONFIG.pushover.apikey, CONFIG.pushover.userkeys)
connect_signals()
options = create_zwave_options(device=device)
network = ZWaveNetwork(options, log=None, autostart=False)
queue = threading.Thread(target=DataQueue.worker,
kwargs={"location": "home.db"},
name="db")
queue.start()
try:
network.start()
# Start REPL with a union where globals override locals
local = locals().copy()
local.update(globals())
code.interact(local=local)
except KeyboardInterrupt:
pass
finally:
logging.info("\nStopping network ...")
network.stop()
logging.info("Stopping data queue ...")
DataQueue.stop()
queue.join()
示例4: print
# 需要导入模块: from openzwave.network import ZWaveNetwork [as 别名]
# 或者: from openzwave.network.ZWaveNetwork import stop [as 别名]
print "------------------------------------------------------------"
#print
#print "------------------------------------------------------------"
#print "Activate the switches on the network"
#print "Nodes in network : %s" % network.nodes_count
#print "------------------------------------------------------------"
#for node in network.nodes:
# for val in network.nodes[node].get_switches() :
# print("Activate switch %s on node %s" % \
# (network.nodes[node].values[val].label,node))
# network.nodes[node].set_switch(val,True)
# print("Sleep 10 seconds")
# time.sleep(10.0)
# print("Dectivate switch %s on node %s" % \
# (network.nodes[node].values[val].label,node))
# network.nodes[node].set_switch(val,False)
#print "%s" % ('Done')
#print "------------------------------------------------------------"
print
print "------------------------------------------------------------"
print "Driver statistics : %s" % network.controller.stats
print "------------------------------------------------------------"
print
print "------------------------------------------------------------"
print "Stop network"
print "------------------------------------------------------------"
network.stop()
示例5: ZWaveControlPlugin
# 需要导入模块: from openzwave.network import ZWaveNetwork [as 别名]
# 或者: from openzwave.network.ZWaveNetwork import stop [as 别名]
class ZWaveControlPlugin(Plugin):
@staticmethod
def get_dependencies():
return []
def __init__(self, object_group, config):
Plugin.__init__(self, config=config, object_group=object_group, plugin_name=PLUGIN_NAME)
# Get parameters from the config file
if not self.is_enabled():
return
# Initialize zwave library
# Options
try:
opts = ZWaveOption(device="/dev/ttyUSB0",
config_path="/home/mlamonta/git/python-openzwave/openzwave/config/",
user_path="logs")
opts.set_log_file("./logs/zwave.log")
opts.set_save_log_level("Alert")
opts.set_append_log_file(False)
opts.set_console_output(False)
opts.set_logging(True)
opts.lock()
except ZWaveException as e:
self.logger.error(str(e))
return
# Network
self.net = ZWaveNetwork(opts)
self.logger.info("------------------------------------------------------------")
self.logger.info("Waiting for network awake : ")
self.logger.info("------------------------------------------------------------")
for i in range(0, 300):
if self.net.state >= self.net.STATE_AWAKED:
self.logger.info("done")
break
else:
time.sleep(1.0)
if self.net.state < self.net.STATE_AWAKED:
self.logger.warning("Network is not awake")
return
self.logger.info("------------------------------------------------------------")
for node in self.net.nodes:
self.logger.info("%s - %s / %s" % (self.net.nodes[node].node_id,
self.net.nodes[node].manufacturer_name,
self.net.nodes[node].product_name) )
self._initialized = True
@staticmethod
def get_template_config(config):
config.add_section(PLUGIN_NAME)
config.set(PLUGIN_NAME, "enabled", "true")
def stop(self):
if self.is_initialized():
self.net.stop()
@staticmethod
def get_dimmer_code(uid, name, current_value):
dimmer_html = """
<div class="col-md-5">
<h2>Dimmer</h2>
<div class="input-group input-group-lg">
<input type="text" class="form-control" name="%s" value="%s"> <!-- DIMMER NAME, VALUE -->
<div class="input-group-btn">
<button name="%s"
type="button"
class="btn btn-primary"
onclick="updateZWave('%s')">Submit</button>
</div>
</div>
<script>
$("input[name='%s']").TouchSpin({
min: 0,
max: 100,
step: 1,
decimals: 0,
boostat: 5,
maxboostedstep: 10,
prefix: "Set:",
postfix: '%%'
});
</script>
</div>
""" % (str(uid),
current_value,
str(uid) + "_btn",
str(uid),
str(uid) )
#.........这里部分代码省略.........
示例6: ZStickInterface
# 需要导入模块: from openzwave.network import ZWaveNetwork [as 别名]
# 或者: from openzwave.network.ZWaveNetwork import stop [as 别名]
class ZStickInterface(object):
def __init__(self):
self.sensor_events = []
self.device = "/dev/ttyACM0"
config_path = "plugins/python-openzwave/openzwave/config"
user_path = "plugins/python-openzwave/config"
# If using older Z-sticks, use the below device:
# self.device = "/dev/ttyUSB0"
# Change config paths where appropriate
self.options = ZWaveOption(self.device, config_path=config_path,
user_path=user_path, cmd_line="")
# Turn off ozw console output
self.options.set_console_output(False)
self.options.set_save_log_level("Info")
self.options.set_logging(False)
self.options.lock()
self.manager = libopenzwave.PyManager()
self.manager.create()
self.manager.addWatcher(self.event_callback)
self.manager.addDriver(self.device)
print("Starting Z-Wave Network...")
self.network = ZWaveNetwork(self.options, log=None)
# Wait for network to start
while not self.network.state >= self.network.STATE_AWAKED:
time.sleep(1)
print("Z-Wave Network Started")
def toggle_switch(self, node_id):
try:
in_work_node = self.network.nodes[node_id]
switch_val = in_work_node.get_switches().keys()[0]
if in_work_node.get_switch_state(switch_val):
in_work_node.set_switch(switch_val, False)
else:
in_work_node.set_switch(switch_val, True)
except:
print("Invalid node id")
def switch(self, node_id, state, function):
try:
in_work_node = self.network.nodes[node_id]
if function == "dimmer":
switch_val = in_work_node.get_dimmers().keys()[0]
if state == "False":
in_work_node.set_dimmer(switch_val, 0)
elif state == "True":
in_work_node.set_dimmer(switch_val, 99)
else:
in_work_node.set_dimmer(switch_val, int(state))
elif function == "switch":
switch_val = in_work_node.get_switches().keys()[0]
if state == "False":
in_work_node.set_switch(switch_val, False)
else:
in_work_node.set_switch(switch_val, True)
except:
print("Invalid node id")
def event_callback(self, args):
if args["notificationType"] in ("ValueAdded", "ValueChanged"):
cmd_class = args["valueId"]["commandClass"]
if cmd_class == "COMMAND_CLASS_SENSOR_BINARY":
node_id = args["valueId"]["nodeId"]
state = args["valueId"]["value"]
data = {"node_id": node_id, "state": state}
self.sensor_events.append(data)
def get_sensor_events(self):
last_events = self.sensor_events
self.sensor_events = []
return last_events
def stop_network(self):
self.network.stop()
示例7: zwave
# 需要导入模块: from openzwave.network import ZWaveNetwork [as 别名]
# 或者: from openzwave.network.ZWaveNetwork import stop [as 别名]
#.........这里部分代码省略.........
# home_id: [0xeefad666] id: [144115188131201026] parent_id: [3] label: [Energy] data: [0.00999999977648]
# value.label = switch
def __init__(self):
pass
def start(self):
#Create a network object
self.network = ZWaveNetwork(self.options, autostart=False)
#We connect to the louie dispatcher
dispatcher.connect(self.louie_network_started, ZWaveNetwork.SIGNAL_NETWORK_STARTED)
dispatcher.connect(self.louie_network_failed, ZWaveNetwork.SIGNAL_NETWORK_FAILED)
dispatcher.connect(self.louie_network_ready, ZWaveNetwork.SIGNAL_NETWORK_READY)
dispatcher.connect(self.louie_scene_message, ZWaveNetwork.SIGNAL_SCENE_EVENT)
dispatcher.connect(self.loui_ess_q_comp, ZWaveNetwork.SIGNAL_ESSENTIAL_NODE_QUERIES_COMPLETE)
dispatcher.connect(self.loui_mess_comp, ZWaveNetwork.SIGNAL_MSG_COMPLETE)
self.network.start()
#We wait for the network.
# print("Waiting for network to become ready : ")
for i in range(0,900):
if self.network.state>=self.network.STATE_READY:
print "Network is ready"
break
else:
sys.stdout.write(".")
sys.stdout.flush()
time.sleep(1.0)
#time.sleep(5.0)
#We update the name of the controller
#print("Update controller name")
#network.controller.node.name = "Hello name"
#time.sleep(5.0)
#We update the location of the controller
#print("Update controller location")
#network.controller.node.location = "Hello location"
# for node in self.network.nodes:
# for val in self.network.nodes[node].get_switches() :
# print("Switch : {}".format(self.network.nodes[node]))
# print("Switch1: {}".format(val))
# 72057594093060096
# 144115188130988032
# network.nodes[node].set_switch(val,True)
#We only activate the first switch
#exit
# for node in self.network.nodes:
# for val in self.network.nodes[node].get_dimmers() :
# print("Dimmer : {}".format(self.network.nodes[node]))
# print("Switch1: {}".format(val))
# 72057594093076481
# 144115188131004513
# 144115188131004417
# 72057594093076577
# network.nodes[node].set_dimmer(val,80)
#We only activate the first dimmer
#exit
def end_network(self):
self.network.stop()
def _set_switch(self,node_id , switch, wert):
if wert == 'Toggle':
cur_val = self.network.nodes[node_id].get_switch_state(switch)
self.network.nodes[node_id].set_switch(switch, not cur_val)
else:
if eval(wert) > 0:
self.network.nodes[node_id].set_switch(switch, True)
else:
self.network.nodes[node_id].set_switch(switch, bool(eval(wert)))
return True
def _set_dimmer(self,node_id , dimmer, wert):
if wert == 'Toggle':
cur_val = self.network.nodes[node_id].get_dimmer_level(dimmer)
if cur_val == 0:
self.network.nodes[node_id].set_dimmer(dimmer, 50)
else:
self.network.nodes[node_id].set_dimmer(dimmer, 0)
else:
self.network.nodes[node_id].set_dimmer(dimmer, eval(wert))
return True
def set_device(self, data_ev):
# TODO do threaded with stop criteria
if data_ev.get('Device') in zw_config.switches:
print data_ev
return self._set_switch(zw_config.switches[data_ev['Device']][0],zw_config.switches[data_ev['Device']][1],data_ev['Value'])
if data_ev.get('Device') in zw_config.dimmer:
print data_ev
return self._set_dimmer(zw_config.dimmer[data_ev['Device']][0],zw_config.dimmer[data_ev['Device']][1],data_ev['Value'])
示例8: Network
# 需要导入模块: from openzwave.network import ZWaveNetwork [as 别名]
# 或者: from openzwave.network.ZWaveNetwork import stop [as 别名]
class Network(object):
_instance = None
def _init(self, device, config, timeout):
self.network = None
self.status = 1
self.timeout = timeout
self.device = device
self.config = config
options = ZWaveOption(self.device, config_path=self.config, user_path=".", cmd_line="")
options.set_log_file("OZW_Log.log")
options.set_append_log_file(False)
options.set_console_output(False)
options.set_save_log_level('Debug')
options.set_logging(True)
options.lock()
self.network = ZWaveNetwork(options, autostart=False)
dispatcher.connect(louie_network_started, ZWaveNetwork.SIGNAL_NETWORK_STARTED)
dispatcher.connect(louie_network_failed, ZWaveNetwork.SIGNAL_NETWORK_FAILED)
dispatcher.connect(louie_network_ready, ZWaveNetwork.SIGNAL_NETWORK_READY)
self.network.start()
def __new__(class_, device=None, config=None, timeout=None):
if not isinstance(class_._instance, class_):
if not device:
return None
class_._instance = object.__new__(class_)
class_._instance._init(device, config, timeout)
return class_._instance
def __del__(self):
self.network.stop()
def __iter__(self):
return self
def next(self):
self.timeout -= 1
if self.timeout == 0:
self.status = 1
raise StopIteration
if self.network.state >= self.network.STATE_READY:
self.status = 0
raise StopIteration
return self.timeout
def get_timout(self):
return self.timeout
def get_status(self):
return self.status
def stop(self):
self.network.stop()
def get_state(self):
return self.network.state
def is_stopped(self):
return self.network.state == self.network.STATE_STOPPED
def is_running(self):
return self.network.state == self.network.STATE_READY
示例9: Backend
# 需要导入模块: from openzwave.network import ZWaveNetwork [as 别名]
# 或者: from openzwave.network.ZWaveNetwork import stop [as 别名]
#.........这里部分代码省略.........
def process_temp_change(self, value):
if value > 25 and not self.get_switch_status(3):
print('too hot - turn on fan')
self.switch_on(3)
elif value < 25 and self.get_switch_status(3):
print('cool enough - turn off fan')
self.switch_off(3)
def log_values(self):
print('Writing sensor log')
try:
t = self.get_temperature()
h = self.get_humidity()
l = self.get_brightness()
with open("sensors.csv", "a") as sensor_log_file:
sensor_log_file.write("%s,%s,%s,%s\n" % (datetime.today().strftime("%d/%m/%Y %H:%M:%S"), t, h, l))
except:
print('Failed to log values')
self.start_timer()
def get_sensor_values(self):
lines = open("sensors.csv", "r").readlines()
return_list = []
for line in lines:
line = line[:-1] # remove newline
d = {'Date': line.split(',')[0], 'Temperature': line.split(',')[1], 'Humidity': line.split(',')[2],
'Lux': line.split(',')[3]}
return_list.append(d)
return return_list
def switch_on(self, name):
print("Activating switch %s" % name)
parsed_id = 0
try:
parsed_id = int(name)
except ValueError:
pass
for key, node in self.network.nodes.iteritems():
if node.name == name or node.node_id == parsed_id:
for val in node.get_switches():
node.set_switch(val, True)
def switch_off(self, name):
print("Deactivating switch %s" % name)
parsed_id = 0
try:
parsed_id = int(name)
except ValueError:
pass
for key, node in self.network.nodes.iteritems():
if node.name == name or node.node_id == parsed_id:
for val in node.get_switches():
node.set_switch(val, False)
def get_switch_status(self, name):
print("Querying switch %s" % name)
parsed_id = 0
try:
parsed_id = int(name)
except ValueError:
pass
for key, node in self.network.nodes.iteritems():
if node.name == name or node.node_id == parsed_id:
for val in node.get_switches():
state = node.get_switch_state(val)
return state
def get_temperature(self):
return self.network.nodes[2].get_sensor_value(TEMPERATURE_VALUE)
def get_humidity(self):
return self.network.nodes[2].get_sensor_value(HUMIDITY_VALUE)
def get_brightness(self):
return self.network.nodes[2].get_sensor_value(LUX_VALUE)
def start_timer(self):
t = Timer(900, self.log_values)
t.start()
def start(self):
global started
if started:
return
started = True
self.network.start()
self.start_timer()
print "Starting..."
for i in range(0, 90):
if self.network.state >= self.network.STATE_READY:
break
else:
sys.stdout.write(".")
sys.stdout.flush()
time.sleep(1.0)
def stop(self):
print "Stopping..."
self.network.stop()
示例10: Backend
# 需要导入模块: from openzwave.network import ZWaveNetwork [as 别名]
# 或者: from openzwave.network.ZWaveNetwork import stop [as 别名]
#.........这里部分代码省略.........
#this method returns an ordered list of the network's nodes
return OrderedDict(sorted(self.network.nodes.items()))
################################################################################################################
######################## START AND STOP THE SOFTWARE REPRESENTATION ############################################
################################################################################################################
def start(self):
# this method starts the software representation
global started
if started:
print "Already started"
return
started = True
self.network.start()
print "Z-Wave Network Starting..."
for i in range(0, 300):
if self.network.is_ready:
break
else:
time.sleep(1.0)
if not self.network.is_ready:
print "Network is not ready but continue anyway"
print "------------------------------------------------------------"
print "Nodes in network : %s" % self.network.nodes_count
print "------------------------------------------------------------"
def stop(self):
# this method stops the software representation
global started
started = False
print "Stopping Z-Wave Network... "
self.network.stop()
def reset(self):
# this method resets the controller node
self.network.controller.hard_reset()
return "Hard Reset Done"
#########################################################################################################################
############## YOUR WORK STARTS HERE ####################################################################################
#########################################################################################################################
#########################################################################################################################
示例11: AlidronOZW
# 需要导入模块: from openzwave.network import ZWaveNetwork [as 别名]
# 或者: from openzwave.network.ZWaveNetwork import stop [as 别名]
#.........这里部分代码省略.........
#
# print nodes_by_name[node_name].is_failed
# return self.network.controller.has_node_failed(node_id)
def network_heal(self, upNodeRoute=False):
logger.info('Healing network')
self.network.heal(upNodeRoute)
def controller_add_node(self, doSecurity=False):
logger.info('Set controller into inclusion mode')
return self.network.controller.add_node(doSecurity)
def controller_remove_node(self):
logger.info('Set controller into exclusion mode')
return self.network.controller.remove_node()
def controller_cancel_command(self):
logger.info('Cancelling controller command')
return self.network.controller.cancel_command()
def node_heal(self, node, upNodeRoute=False):
logger.info('Healing node %s', self._node_name(node))
return node.heal(upNodeRoute)
def node_is_failed(self, node):
logger.info('Asking if node %s is failed (%s)', self._node_name(node), node.is_failed)
return node.is_failed
# Tooling
@staticmethod
def _replace_all(s, olds, new):
return reduce(lambda s, old: s.replace(old, new), list(olds), s)
def _node_name(self, node):
return node.name if node.name else str(node.node_id)
def _value_data(self, value):
data = value.data
logger.debug('data type is %s', type(data))
if type(data) is str:
try:
data.decode()
except UnicodeDecodeError:
data = binascii.b2a_base64(data)
return data
def _make_uri(self, node, value):
def _values_by_index(values):
per_idx = {}
for value in values:
idx = value.index
if idx not in per_idx:
per_idx[idx] = []
per_idx[idx].append(value)
return per_idx
ok = False
while not ok:
try:
values_by_idx = _values_by_index(node.get_values(class_id=value.command_class).values())
ok = True
except RuntimeError as ex:
if ex.message == 'dictionary changed size during iteration':
continue
else:
raise
is_multi_instance = len(values_by_idx[value.index]) > 1
cmd_class = node.get_command_class_as_string(value.command_class)
cmd_class = cmd_class.replace('COMMAND_CLASS_', '').lower()
node_name = self._node_name(node)
label = self._replace_all(value.label.lower(), ' /()%:', '_').strip('_')
if is_multi_instance:
uri = 'zwave://%s.%s/%s/%d/%s' % (
node._network.home_id_str, node_name, cmd_class, value.instance, label)
else:
uri = 'zwave://%s.%s/%s/%s' % (
node._network.home_id_str, node_name, cmd_class, label)
return str(uri)
# Lifecycle
def shutdown(self):
# Stopping internal notification reader greenlet
self._running = False
self._ozw_notif_queue.put(None)
self.network.stop()
logger.info('Stopped network')
self.network.destroy()
logger.info('Destroyed network')
self.isac_node.shutdown()
logger.info('Stopped ISAC node')
示例12: TestApi
# 需要导入模块: from openzwave.network import ZWaveNetwork [as 别名]
# 或者: from openzwave.network.ZWaveNetwork import stop [as 别名]
class TestApi(TestPyZWave):
"""
Parent test class for api
"""
@classmethod
def setUpClass(self):
super(TestApi, self).setUpClass()
self.options = ZWaveOption(device=self.device, user_path=self.userpath)
self.options.set_log_file("OZW_Log.log")
self.options.set_append_log_file(False)
self.options.set_console_output(self.ozwout)
self.options.set_save_log_level(self.ozwlog)
self.options.set_logging(True)
self.options.lock()
self.node_result = None
dispatcher.connect(self.node_update, ZWaveNetwork.SIGNAL_NODE)
self.network = ZWaveNetwork(self.options)
self.ctrl_command_result = None
self.ctrl_command_signal = None
#dispatcher.connect(self.ctrl_message, ZWaveNetwork.SIGNAL_CONTROLLER_COMMAND)
time.sleep(1.0)
@classmethod
def tearDownClass(self):
self.network.stop()
time.sleep(2.0)
self.network.destroy()
time.sleep(1.0)
super(TestApi, self).tearDownClass()
self.network = None
def setUp(self):
self.wait_for_network_state(self.network.STATE_AWAKED, 1)
def wait_for_queue(self):
for i in range(0,60):
if self.network.controller.send_queue_count <= 0:
break
else:
time.sleep(0.5)
def wait_for_network_state(self, state, multiply=1):
for i in range(0,SLEEP*multiply):
if self.network.state>=state:
break
else:
time.sleep(1.0)
def ctrl_message(self, network, controller, node, node_id,
state_int, state, state_full,
error_int, error, error_full,):
self.ctrl_state_result = state
self.ctrl_command_signal = {
'network':network,
'controller':controller,
'node':node,
'node_id':node_id,
'state_int':state_int,
'state':state,
'state_full':state_full,
'error_int':error_int,
'error':error,
'error_full':error_full,
}
def ctrl_waiting(self, network, controller,
state_int, state, state_full):
self.ctrl_state_result = state
def node_update(self, network, node):
self.node_result = node
示例13: ZWaveManager
# 需要导入模块: from openzwave.network import ZWaveNetwork [as 别名]
# 或者: from openzwave.network.ZWaveNetwork import stop [as 别名]
#.........这里部分代码省略.........
return switches
def get_dimmers_from_location(self, location):
values = {}
dimmers = []
for node in self.network.nodes:
for val in self.network.nodes[node].get_dimmers() :
if self.network.nodes[node].location == location:
dimmer = {}
dimmer['name']=self.network.nodes[node].name
dimmer['type']='dimmer'
dimmer['node']=node
dimmer['level']=self.network.nodes[node].get_dimmer_level(val)
dimmer['state']=dimmer['level']>0
dimmers.append( dimmer)
return dimmers
def get_lights_from_location(self, location):
lights = []
for switch in self.get_switches_from_location( location ):
lights.append(switch)
for dimmer in self.get_dimmers_from_location( location ):
lights.append(dimmer)
return lights
def get_switch_state( self, node ):
node=int(node)
for val in self.network.nodes[node].get_switches():
return self.network.nodes[node].get_switch_state(val)
def get_dimmer_level( self, node ):
node=int(node)
for val in self.network.nodes[node].get_dimmers():
return self.network.nodes[node].get_dimmer_level(val)
def light_on(self,node):
node=int(node)
for val in self.network.nodes[node].get_switches() : self.network.nodes[node].set_switch(val,True)
print "Node %s, Switch on" % (str(node))
def light_off(self,node):
node=int(node)
for val in self.network.nodes[node].get_switches() : self.network.nodes[node].set_switch(val,False)
print "Node %s, Switch off" % (str(node))
def set_dimmer(self,node,level):
# level : a value between 0-99 or 255. 255 set the level to the last value. 0 turn the dimmer off
node=int(node)
level=int(level)
for val in self.network.nodes[node].get_dimmers() :
self.network.nodes[node].set_dimmer(val,level)
self.network.nodes[node].set_dimmer(val,level)
self.network.nodes[node].set_dimmer(val,level)
print "Node %s, Dimmer set to %s" % (str(node), str(level))
def all_lights_on(self):
for node in self.network.nodes:
for val in self.network.nodes[node].get_switches() : self.network.nodes[node].set_switch(val,True)
def all_lights_off(self):
for node in self.network.nodes:
for val in self.network.nodes[node].get_switches() : self.network.nodes[node].set_switch(val,False)
def shutdown(self):
self.network.stop()
def test(self):
return "life"
def ozw_library_version(self):
return self.network.controller.ozw_library_version
def python_ozw_library_version(self):
return self.network.controller.python_library_version
def zw_library_version(self):
return self.network.controller.library_description
def home_id(self):
return self.network.home_id_str
def controller_node_id(self):
return self.network.controller.node.node_id
def controller_node_version(self):
return self.network.controller.node.version
def nodes(self):
return self.network.nodes_count
def controller_capabilities(self):
return self.network.controller.capabilities
def controller_node_capabilities(self):
return self.network.controller.node.capabilities
def controller_stats(self):
return self.network.controller.stats