Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #225 from danielperna84/devel
Browse files Browse the repository at this point in the history
0.1.56
  • Loading branch information
danielperna84 authored Feb 19, 2019
2 parents e298897 + 40eb5e1 commit 9d438bb
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 140 deletions.
8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Version 0.1.56 (2019-)
- Remove SABOTAGE from HmIP-SMO(-A) (Issue #212) @danielperna84
- Fix resolving names with JSON with SSL @danielperna84
- Added PRESS_* events to IP Powermeter switches @dagobert
- Added OPERATING_VOLTAGE to some IP devices @dagobert
- Fix LOWBAT-Helper for IP shutter contact @dagobert
- Code cleanup @dagobert, @danielperna84

Version 0.1.55 (2019-01-24)
- Add support for HmIP-MIOB @danielperna84
- Add suppoer for HmIP-BSL @danielperna84
Expand Down
20 changes: 12 additions & 8 deletions pyhomematic/_hm.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
BACKEND_UNKNOWN = 0
BACKEND_CCU = 1
BACKEND_HOMEGEAR = 2
WORKING = False


# Device-storage
devices = {}
devices_all = {}
devices_raw = {}
devices_raw_dict = {}
working = False


def make_http_credentials(username=None, password=None):
Expand All @@ -63,7 +63,7 @@ def make_http_credentials(username=None, password=None):

def build_api_url(host=REMOTES['default']['ip'],
port=REMOTES['default']['port'],
path=REMOTES['default']['port'],
path=REMOTES['default']['path'],
username=None,
password=None,
ssl=False):
Expand Down Expand Up @@ -132,19 +132,22 @@ def __init__(self,
if fcontent:
self._devices_raw[remote] = json.loads(fcontent)

# Continue if there are no stored devices
if not self._devices_raw.get(remote):
continue
for device in self._devices_raw[remote]:
self._devices_raw_dict[remote][device['ADDRESS']] = device
LOG.debug("RPCFunctions.__init__: devices_raw = %s" %
(str(self._devices_raw[remote]), ))

# Create the "interactive" device-objects and store them in
# self._devices and self._devices_all
# Create the "interactive" device-objects from cache and store
# them in self._devices and self._devices_all
self.createDeviceObjects(interface_id)

def createDeviceObjects(self, interface_id):
"""Transform the raw device descriptions into instances of devicetypes.generic.HMDevice or availabe subclass."""
global working
working = True
global WORKING
WORKING = True
remote = interface_id.split('-')[-1]
LOG.debug(
"RPCFunctions.createDeviceObjects: iterating interface_id = %s" % (remote, ))
Expand Down Expand Up @@ -187,7 +190,7 @@ def createDeviceObjects(self, interface_id):
"RPCFunctions.createDeviceObjects: Child: %s", str(err))
if self.devices_all[remote] and self.remotes[remote].get('resolvenames', False):
self.addDeviceNames(remote)
working = False
WORKING = False
if self.systemcallback:
self.systemcallback('createDeviceObjects')
return True
Expand Down Expand Up @@ -363,7 +366,7 @@ def addDeviceNames(self, remote):
interface = False
if response['error'] is None and response['result']:
for i in response['result']:
if i['port'] == self.remotes[remote]['port']:
if i['port'] in [self.remotes[remote]['port'], self.remotes[remote]['port'] + 30000]:
interface = i['name']
break
LOG.debug(
Expand Down Expand Up @@ -402,6 +405,7 @@ def addDeviceNames(self, remote):

# Then try to get names from XML-API
elif self.remotes[remote]['resolvenames'] == 'xml':
LOG.warning("Resolving names with the XML-API addon will be disabled in a future release. Please switch to json.")
try:
response = urllib.request.urlopen(
"http://%s%s" % (self.remotes[remote]['ip'], XML_API_URL), timeout=5)
Expand Down
3 changes: 3 additions & 0 deletions pyhomematic/devicetypes/actors.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ class IPSwitchPowermeter(IPSwitch, HMSensor, HelperRssiDevice):
def __init__(self, device_description, proxy, resolveparamsets=False):
super().__init__(device_description, proxy, resolveparamsets)

self.EVENTNODE.update({"PRESS_SHORT": [1, 2],
"PRESS_LONG": [1, 2]})

# init metadata
sensorIndex = None
if "HmIP-FSM" in self.TYPE or "HmIP-FSM16" in self.TYPE:
Expand Down
6 changes: 4 additions & 2 deletions pyhomematic/devicetypes/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ def getWriteData(self, name, channel=None):

def _getNodeData(self, name, metadata, channel=None):
""" Returns a data point from data"""
nodeChannel = None
if name in metadata:
nodeChannelList = metadata[name]
if len(nodeChannelList) > 1:
Expand All @@ -332,7 +333,7 @@ def _getNodeData(self, name, metadata, channel=None):
else:
LOG.warning("HMDevice._getNodeData: %s not found in %s, empty nodeChannelList" % (name, metadata))
return None
if nodeChannel in self.CHANNELS:
if nodeChannel is not None and nodeChannel in self.CHANNELS:
return self._hmchannels[nodeChannel].getValue(name)

LOG.error("HMDevice._getNodeData: %s not found in %s" % (name, metadata))
Expand All @@ -346,13 +347,14 @@ def actionNodeData(self, name, data, channel=None):

def _setNodeData(self, name, metadata, data, channel=None):
""" Returns a data point from data"""
nodeChannel = None
if name in metadata:
nodeChannelList = metadata[name]
if len(nodeChannelList) > 1:
nodeChannel = channel if channel is not None else nodeChannelList[0]
elif len(nodeChannelList) == 1:
nodeChannel = nodeChannelList[0]
if nodeChannel in self.CHANNELS:
if nodeChannel is not None and nodeChannel in self.CHANNELS:
return self._hmchannels[nodeChannel].setValue(name, data)

LOG.error("HMDevice.setNodeData: %s not found with value %s on %i" %
Expand Down
13 changes: 13 additions & 0 deletions pyhomematic/devicetypes/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ def low_batt(self, channel=None):
return self.getAttributeData("LOW_BAT", channel)


class HelperOperatingVoltageIP(HMDevice):
"""This Helper adds easy access to read the OPERATING_VOLTAGE state"""
def __init__(self, device_description, proxy, resolveparamsets=False):
super().__init__(device_description, proxy, resolveparamsets)

# init metadata
self.ATTRIBUTENODE.update({"OPERATING_VOLTAGE": [0]})

def operation_voltage(self, channel=None):
""" Returns the operating voltage. """
return float(self.getAttributeData("OPERATING_VOLTAGE", channel))


class HelperWorking(HMDevice):
"""This helper provides access to the WORKING state of some devices."""
def __init__(self, device_description, proxy, resolveparamsets=False):
Expand Down
Loading

0 comments on commit 9d438bb

Please sign in to comment.