Skip to content

Commit

Permalink
Updated files to Python 3 and latest RP framework
Browse files Browse the repository at this point in the history
  • Loading branch information
RogueProeliator committed Apr 2, 2023
1 parent aab196e commit eb5d6c1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 83 deletions.
Expand Up @@ -8,33 +8,22 @@
This module works with both Python 2 and 3.
"""

from __future__ import unicode_literals

__version__ = '1.7.4'
version = __version__

from random import randint
import collections
import numbers
import logging
import indigo
from xml.dom.minidom import parseString

__version__ = '1.7.4'
version = __version__

LOG = logging.getLogger("dicttoxml")

# python 3 doesn't have a unicode type
try:
unicode
except:
unicode = str

# python 3 doesn't have a long type
try:
long
except:
long = int
# python 3 doesn't have a unicode or long type
unicode = str
long = int


def set_debug(debug=True, filename='dicttoxml.log'):
Expand All @@ -59,9 +48,11 @@ def unicode_me(something):
return unicode(something, 'utf-8')
except:
return unicode(something)


ids = [] # initialize list of unique ids

# initialize list of unique ids
ids = []


def make_id(element, start=100000, end=999999):
"""Returns a random integer"""
Expand Down
@@ -1,27 +1,17 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# /////////////////////////////////////////////////////////////////////////////////////////
# /////////////////////////////////////////////////////////////////////////////////////////
#######################################################################################
# Domotics Pad Client Plugin by RogueProeliator <adam@duncanwaredevelopment.com>
# /////////////////////////////////////////////////////////////////////////////////////////
# /////////////////////////////////////////////////////////////////////////////////////////
#######################################################################################

# /////////////////////////////////////////////////////////////////////////////////////////
# Python imports
# /////////////////////////////////////////////////////////////////////////////////////////
import RPFramework
from RPFramework.RPFrameworkNonCommChildDevice import RPFrameworkNonCommChildDevice


# /////////////////////////////////////////////////////////////////////////////////////////
# /////////////////////////////////////////////////////////////////////////////////////////
# DomoPadAndroidClient
# /////////////////////////////////////////////////////////////////////////////////////////
# /////////////////////////////////////////////////////////////////////////////////////////
class DomoPadAndroidClient(RPFramework.RPFrameworkNonCommChildDevice):
class DomoPadAndroidClient(RPFrameworkNonCommChildDevice):

# /////////////////////////////////////////////////////////////////////////////////////
#######################################################################################
# Class construction and destruction methods
# /////////////////////////////////////////////////////////////////////////////////////
#######################################################################################
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Constructor called once upon plugin class receiving a command to start device
# communication. The plugin will call other commands when needed, simply zero out the
Expand All @@ -30,20 +20,20 @@ class DomoPadAndroidClient(RPFramework.RPFrameworkNonCommChildDevice):
def __init__(self, plugin, device):
super().__init__(plugin, device)

self.upgradedDeviceProperties.append(("SupportsBatteryLevel", True))
self.upgraded_device_properties.append(("SupportsBatteryLevel", True))

self.upgradedDeviceStates.append("modelName")
self.upgradedDeviceStates.append("batteryStatus")
self.upgradedDeviceStates.append("batteryLevel")
self.upgradedDeviceStates.append("longitude")
self.upgradedDeviceStates.append("latitude")
self.upgradedDeviceStates.append("locationFixTime")
self.upgraded_device_states.append("modelName")
self.upgraded_device_states.append("batteryStatus")
self.upgraded_device_states.append("batteryLevel")
self.upgraded_device_states.append("longitude")
self.upgraded_device_states.append("latitude")
self.upgraded_device_states.append("locationFixTime")

# /////////////////////////////////////////////////////////////////////////////////////
#######################################################################################
# Overridden communications functions
# /////////////////////////////////////////////////////////////////////////////////////
def initiateCommunications(self):
super(DomoPadAndroidClient, self).initiateCommunications()
#######################################################################################
def initiate_communications(self):
super().initiate_communications()

# update the state of the device to reflect the pairing status...
current_pairing_prop = self.indigoDevice.pluginProps.get("deviceRegistrationId", "")
Expand All @@ -54,24 +44,17 @@ def initiateCommunications(self):
self.indigoDevice.updateStateOnServer("isPaired", True, uiValue="Paired")


# /////////////////////////////////////////////////////////////////////////////////////////
# /////////////////////////////////////////////////////////////////////////////////////////
# VideoCameraFeed
# Handles the specification of a video feed that can be shown within HousePad, such as
# to show live security camera feeds
# /////////////////////////////////////////////////////////////////////////////////////////
# /////////////////////////////////////////////////////////////////////////////////////////
class VideoCameraFeed(RPFramework.RPFrameworkNonCommChildDevice):
class VideoCameraFeed(RPFrameworkNonCommChildDevice):

# /////////////////////////////////////////////////////////////////////////////////////
#######################################################################################
# Class construction and destruction methods
# /////////////////////////////////////////////////////////////////////////////////////
#######################################################################################
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Constructor called once upon plugin class receiving a command to start device
# communication. The plugin will call other commands when needed, simply zero out the
# member variables
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def __init__(self, plugin, device):
super(VideoCameraFeed, self).__init__(plugin, device)
super().__init__(plugin, device)


@@ -1,21 +1,18 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#/////////////////////////////////////////////////////////////////////////////////////////
#######################################################################################
# Domotics Pad Google Client Plugin by RogueProeliator <rp@rogueproeliator.com>
# See plugin.py for more plugin details and information
#/////////////////////////////////////////////////////////////////////////////////////////
#######################################################################################

#/////////////////////////////////////////////////////////////////////////////////////////
# Python imports
#/////////////////////////////////////////////////////////////////////////////////////////
import indigo

#/////////////////////////////////////////////////////////////////////////////////////////
#######################################################################################
# GoogleDeviceTypesDefinition
# Dictionary which defines the available Google Home device types and stores the
# recommended traits to support for the device type in order to allow the most complete
# control/user experience "out of the box"
#/////////////////////////////////////////////////////////////////////////////////////////
# Dictionary which defines the available Google Home device types and stores the
# recommended traits to support for the device type in order to allow the most complete
# control/user experience "out of the box"
#######################################################################################
googleDeviceTypesDefn = {
'action.devices.types.DOOR':
{'Device': 'Door', 'DeviceType': 'action.devices.types.DOOR',
Expand Down Expand Up @@ -81,10 +78,10 @@ def map_to_google_device_type(device):
return ''


#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Maps an Indigo device (object) to the proper/default Google Assistant device type
# that may be found in the types dictionary
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def get_subtypes_for_device(device):
try:
subtype_meta = SUPPORTED_INDIGO_CLASSES[device.__class__]
Expand All @@ -99,10 +96,10 @@ def get_subtypes_for_device(device):
return [("invalid", "invalid device type")]


#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Determines the sub type of a device based upon a specified sub type, a device
# property or hints based upon device properties
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def get_subtype(device):
if device.__class__ not in SUPPORTED_INDIGO_CLASSES or SUPPORTED_INDIGO_CLASSES[device.__class__] is None:
return None
Expand Down Expand Up @@ -312,18 +309,18 @@ def build_google_state_update(device):
# commands may be present. The return is the results of the action in the format
# expected by the Google Assistant for this particular execute command
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def processExecuteRequest(commandsList):
def process_execute_request(commands_list):
# the response object contains a list of devices that fall into each status; this will
# be a dictionary of status with a value being the list of devices
device_status_results = {}

# there may be multiple commands to execute in the array
for commandDefn in commandsList:
for commandDefn in commands_list:
# build the list of devices against which we must execute the
# command(s) provided
devices_list = []
for deviceId in commandDefn['devices']:
indigo_device = indigo.devices[int(deviceId['id'])]
for device_id in commandDefn['devices']:
indigo_device = indigo.devices[int(device_id['id'])]
devices_list.append(indigo_device)
if indigo_device.id not in device_status_results:
device_status_results[indigo_device.id] = ''
Expand All @@ -338,10 +335,10 @@ def processExecuteRequest(commandsList):
if not is_device_online:
device_status_results[device.id] = 'OFFLINE'
else:
for execCommand in commandDefn['execution']:
command_id = execCommand['command']
for exec_command in commandDefn['execution']:
command_id = exec_command['command']
if command_id == 'action.devices.commands.OnOff':
if execCommand['params']['on']:
if exec_command['params']['on']:
indigo.device.turnOn(device.id)
else:
indigo.device.turnOff(device.id)
Expand All @@ -360,15 +357,15 @@ def processExecuteRequest(commandsList):
offline_devices = {'ids': [], 'status': 'OFFLINE'}

# add each device result to the appropriate list
for deviceId, result in device_status_results.items():
for device_id, result in device_status_results.items():
if result == 'SUCCESS':
success_devices['ids'].append(str(deviceId))
success_devices['ids'].append(str(device_id))
elif result == 'PENDING':
pending_devices['ids'].append(str(deviceId))
pending_devices['ids'].append(str(device_id))
elif result == 'ERROR':
error_devices['ids'].append(str(deviceId))
error_devices['ids'].append(str(device_id))
elif result == 'offlineDevices':
offline_devices['ids'].append(str(deviceId))
offline_devices['ids'].append(str(device_id))

# build the composite results array
if len(success_devices['ids']) > 0:
Expand Down

0 comments on commit eb5d6c1

Please sign in to comment.