Created
March 10, 2019 13:22
-
-
Save DaleGia/55ba704df12cd4b2284871e0686b7f9c to your computer and use it in GitHub Desktop.
Node1Management Management Node Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def TurnOn(arg = None): | |
print("Turning Tv and DVD On") | |
lookup_remote_action("Node2TvTurnOn").call() | |
lookup_remote_action("Node3DvdTurnOn").call() | |
def UpdateStatus(message): | |
print('Management Status: Status requested') | |
tvMessage = lookup_remote_event("TvStatus").getArg().get('message') | |
dvdMessage = lookup_remote_event("DvdStatus").getArg().get('message') | |
aggregateMessage = "TvStatus: " + tvMessage + ' - ' + "DvdStatus: " + dvdMessage | |
lookup_local_event("TvStatus").emit({'message': tvMessage}) | |
lookup_local_event("DvdStatus").emit({'message': dvdMessage}) | |
lookup_local_event("ManagementStatus").emit({'message': aggregateMessage}) | |
statusMetadata = {'Group': 'Status', 'schema': | |
{'title': '', 'type': 'array', 'items': | |
{'type': 'object', 'properties': | |
{ | |
'message': {'type': 'string'}, | |
} | |
} | |
}} | |
def main(arg = None): | |
print("Node started...") | |
create_local_action("TurnOn", TurnOn, None) | |
create_remote_action("Node2TvTurnOn", None, "Node2Tv", "TurnOn") | |
create_remote_action("Node3DvdTurnOn", None, "Node3Dvd", "TurnOn") | |
statusMetadata['schema']['title'] = 'ManagementStatus' | |
create_local_event("ManagementStatus", statusMetadata) | |
statusMetadata['schema']['title'] = 'TvStatus' | |
create_local_event("TvStatus", statusMetadata) | |
statusMetadata['schema']['title'] = 'DvdStatus' | |
create_local_event("DvdStatus", statusMetadata) | |
create_remote_event("TvStatus", UpdateStatus, None, "Node2Tv", "TvStatus") | |
create_remote_event("DvdStatus", UpdateStatus, None, "Node3Dvd", "DvdStatus") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment