Created
March 10, 2019 13:14
-
-
Save DaleGia/68457ba6adc28c9578e7656e97820c0d to your computer and use it in GitHub Desktop.
Node2Tv Device 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
# Only required for placeholder status function | |
import random | |
def TurnOn(arg = None): | |
print("Turning Tv On") | |
print("Turning Tv On function not yet implemented. Doing nothing...") | |
UpdateStatus(); | |
def UpdateStatus(arg = None): | |
print('TV Status: Status requested') | |
print('UpdateStatus function not yet implemented, emiting random message...') | |
if(random.choice([True, False])): | |
message = {'message': 'ok'} | |
else: | |
message = {'message': 'not ok: randomly generated status is not okay...'} | |
lookup_local_event("TvStatus").emit(message) | |
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) | |
statusMetadata['schema']['title'] = 'TvStatus' | |
create_local_event("TvStatus", statusMetadata) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment