Dateien hochladen nach „“

special command
This commit is contained in:
Manuel Kamper 2023-05-22 08:22:27 +00:00
parent e9c4ef2f28
commit 6e43bb64d1
2 changed files with 38 additions and 28 deletions

View File

@ -1,20 +1,21 @@
configs = {
'country': 'AT',
'ntp_host': 'pool.ntp.org',
'gmt_offset': 1,
'auto_summertime': True,
'disable_wifi_powersavingmode': True,
'api_port': 80,
'hostname': 'tcs2fhem',
'displayoff': 5,
'log_incoming_bus_messages': True,
'log_housekeeping_days': 7,
'frontdoor_ringing_message': [1, 2, 2, 0, 0, 1],
'door_ringing_message': [1, 2, 2, 0, 0, 2],
'door_trigger_message': [1, 2, 2, 0],
'light_trigger_message': [1, 2, 2, 1],
'tcs_message': [1, 2, 2, 0, 1],
'api_client_ip': '10.0.3.5',
'fhem_door_ringed': 'http://fhem-server:8086/fhem?cmd=set%20TCS_Door%20ringed&XHR=1',
'fhem_frontdoor_ringed': 'http://fhem-server:8086/fhem?cmd=set%20TCS_FrontDoor%20ringed&XHR=1',
configs = {
'country': 'AT',
'ntp_host': 'pool.ntp.org',
'gmt_offset': 1,
'auto_summertime': True,
'disable_wifi_powersavingmode': True,
'api_port': 80,
'hostname': 'tcs2fhem',
'displayoff': 5,
'log_incoming_bus_messages': True,
'log_housekeeping_days': 7,
'frontdoor_ringing_message': [1, 2, 2, 0, 0, 1],
'door_ringing_message': [1, 2, 2, 0, 0, 2],
'door_trigger_message': [1, 2, 2, 0],
'light_trigger_message': [1, 2, 2, 1],
'tcs_message': [1, 2, 2, 0, 1],
'api_client_ip': '10.0.3.5',
'fhem_door_ringed': 'http://fhem-server:8086/fhem?cmd=set%20TCS_Door%20ringed&XHR=1',
'fhem_frontdoor_ringed': 'http://fhem-server:8086/fhem?cmd=set%20TCS_FrontDoor%20ringed&XHR=1',
'fhem_special_command': 'http://fhem-server:8086/fhem?cmd=set%20VZ_Tuerschloss%20unlock&XHR=1',
}

27
main.py
View File

@ -255,34 +255,37 @@ async def APIHandling(reader, writer):
if (req[2] == "triggerdoor"):
Logger.LogMessage("Triggering Door")
await TCSBusWriter(configs['door_trigger_message'])
stateis = "Triggered front door opener"
stateis = "Triggered: front door opener"
elif (req[2] == "triggerlight"):
Logger.LogMessage("Triggering Licht")
await TCSBusWriter(configs['light_trigger_message'])
stateis = "Triggered light"
stateis = "Triggered: light"
elif (req[2] == "togglepartymode"):
TogglePartyMode()
stateis = "Toggled Party-Mode"
stateis = "Toggled: Party-Mode"
elif (req[2] == "partymodeon"):
SetPartyMode(True)
stateis = "Enabled Party-Mode"
stateis = "Enabled: Party-Mode"
elif (req[2] == "partymodeoff"):
SetPartyMode(False)
stateis = "Disabled Party-Mode"
stateis = "Disabled: Party-Mode"
elif (req[2] == "partymodestate"):
stateis = "Party-Mode is " + PartyModeState()
elif (req[2] == "ping"):
stateis = "OK"
stateis = "Ping: OK"
elif (req[2] == "specialcommand"):
ExternalAPI("special")
stateis = "Special command: executed"
elif (req[2] == "stats"):
stateis = "IP address: " + Networking.GetIPAddress() + "<br>MAC address: " + Networking.GetMACAddress() + "<br>Hostname: " + configs['hostname'] + "<br>API Port: " + str(configs['api_port']) + "<br>Uptime (h:m): " + Uptime() + "<br>Date/Time: " + TimeUtils.DateTimeNow() + "<br>Version: " + version + "<br>GMT Timezone Offset (hours): " + str(configs['gmt_offset']) + "<br>Auto summertime: " + str(configs['auto_summertime']) + "<br>Display off time (mins): " + str(configs['displayoff']) + "<br>Log incoming bus messages: " + str(configs['log_incoming_bus_messages']) + "<br>Housekeep logfiles after days: " + str(configs['log_housekeeping_days']) + "<br>Message 'Front door ringing': " + str(configs['frontdoor_ringing_message']) + "<br>Message 'Door ringing': " + str(configs['door_ringing_message']) + "<br>Message 'Door opener triggered': " + str(configs['door_trigger_message']) + "<br>Message 'Light triggered': " + str(configs['light_trigger_message']) + "<br>CPU frequency (MHz): " + str(machine.freq()/1000000) + "<br>Party-Mode is: " + PartyModeState()
elif (req[2] == "reboot"):
stateis = "Rebooting device now..."
stateis = "Rebooting device: now..."
Reboot()
elif (req[2] == "ringdoor"):
stateis = "Ringing doorbell"
stateis = "Ringing: doorbell"
await TCSBusWriter(configs['door_ringing_message'])
elif (req[2] == "ringfrontdoor"):
stateis = "Ringing front doorbell"
stateis = "Ringing: front doorbell"
await TCSBusWriter(configs['frontdoor_ringing_message'])
elif (req[2] == "logs"):
if (len(req) >= 4 and req[3] != "json"):
@ -431,6 +434,12 @@ async def ExternalAPI(action):
response.close()
else:
Logger.LogMessage("Warning: No fhem_frontdoor_ringed setting!")
elif (action == "special"):
if (configs['fhem_special_command'] is not ""):
response = requests.get(configs['fhem_special_command'])
response.close()
else:
Logger.LogMessage("Warning: No fhem_special_command setting!")
else:
Logger.LogMessage("Error: Unknown ExternalAPI action!")
pass