def test_manager_ccu_init(self, ccu): builtins.manager_ccu = ccu new_ccu = pmatic.CCU() assert new_ccu == ccu assert new_ccu.api == ccu.api assert isinstance(new_ccu.api, pmatic.api.AbstractAPI) del builtins.__dict__["manager_ccu"] assert not hasattr(builtins, "manager_ccu") new_ccu = pmatic.CCU() assert new_ccu != ccu
def _get_test_ccu(self, API): self._monkeypatch = monkeypatch() self._monkeypatch.setattr(pmatic.api, 'init', lambda: None) ccu = pmatic.CCU() ccu.api = API return ccu
# # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import pmatic import ccudata ccu = pmatic.CCU( address=ccudata.address, credentials=ccudata.credentials, connect_timeout=ccudata.connect_timeout, ) # Trigger a short button press for the first button of a HM-PBI-4-FM device for device in ccu.devices.query(device_name=u"Büro-Schalter"): if device.switch1.press_short(): print("done.") else: print("failed!")
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import pmatic import sys # Open up a remote connection via HTTP to the CCU and login as admin. When the connection # can not be established within 5 seconds it raises an exception. ccu = pmatic.CCU( address= "http://192.168.1.26", # TODO: Replace this with the URL to your CCU2. credentials=("Admin", "EPIC-SECRET-PW"), # TODO: Insert your credentials here. connect_timeout=5) sys.stdout.write("Switching off all lamps...\n") # Search all devices which contain the text "Lampe" in their name, then # switch all of them off and report the result. for device in ccu.devices.query(device_name_regex=".*Lampe.*"): sys.stdout.write(" %s..." % device.name) if device.switch_off(): sys.stdout.write("done.\n") else: sys.stdout.write("failed!\n") sys.stdout.write("Finished.\n")
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Pmatic has a concept of persons and the presence of persons. For each # person multiple devices can be configured which can then be used to # detect the presence of a person. It is implemented as plugin mechanism # which can be extended easily. For the start there is a plugin to control # a persons availability by a device which is connected withe a fritz!Box # in your local network. import pmatic ccu = pmatic.CCU(address="http://192.168.1.26", credentials=("Admin", "EPIC-SECRET-PW")) # Maybe you need to configure your fritz!Box credentials to be able to fetch the # presence information of the configured devices. from pmatic.residents import PersonalDeviceFritzBoxHost PersonalDeviceFritzBoxHost.configure("fritz.box", password="******") # Now load some resident data. ccu.residents.from_config({ "residents": [{ "id": 0, "name": "Lars", "email": "",
This detection is using the events sent by the CCU. So the state changes are detected nearly instantly. The script prints out a warning message for each detected too long open shutter contact. You can easily adapt the script to do anything else instead of just printing a message. """ import time import pmatic #pmatic.logging(pmatic.DEBUG) ccu = pmatic.CCU( address="http://192.168.1.26", credentials=("Admin", "EPIC-SECRET-PW"), connect_timeout=5, ) # Get all HM-Sec-SC (shutter contact) devices devices = ccu.devices.query(device_type="HM-Sec-SC") # This function is executed on each state change def print_summary_state(param): # Format the time of last change for printing last_changed = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(param.last_changed)) print( "%s %s %s" % (last_changed, param.channel.device.name, param.channel.summary_state))
from __future__ import print_function from __future__ import unicode_literals import sys, traceback import pmatic from pmatic.notify import Pushover from pmatic.manager import Config if not pmatic.utils.is_manager_inline(): print( "This script can only be called from the pmatic Manager as inline script." ) sys.exit(0) ccu = pmatic.CCU() # Create a list of all devices having a low battery low = [] for device in ccu.devices: if device.is_battery_low: low.append(device.name) if not low: print("All battery powered devices are fine.") sys.exit(0) print("Found low batteries: %s" % ", ".join(low)) # Load the resident to inform lars = ccu.residents.get_by_name("Lars")