def setup(hass, config): """Activate Tahoma component.""" from tahoma_api import TahomaApi conf = config[DOMAIN] username = conf.get(CONF_USERNAME) password = conf.get(CONF_PASSWORD) exclude = conf.get(CONF_EXCLUDE) try: api = TahomaApi(username, password) except RequestException: _LOGGER.exception("Error communicating with Tahoma API") return False try: api.get_setup() devices = api.get_devices() except RequestException: _LOGGER.exception("Cannot fetch information from Tahoma API") return False hass.data[DOMAIN] = { 'controller': api, 'devices': defaultdict(list) } for device in devices: _device = api.get_device(device) if all(ext not in _device.type for ext in exclude): device_type = map_tahoma_device(_device) if device_type is None: _LOGGER.warning('Unsupported type %s for Tahoma device %s', _device.type, _device.label) continue hass.data[DOMAIN]['devices'][device_type].append(_device) for component in TAHOMA_COMPONENTS: discovery.load_platform(hass, component, DOMAIN, {}, config) return True
def setup(hass, config): """Activate Tahoma component.""" from tahoma_api import TahomaApi conf = config[DOMAIN] username = conf.get(CONF_USERNAME) password = conf.get(CONF_PASSWORD) exclude = conf.get(CONF_EXCLUDE) try: api = TahomaApi(username, password) except RequestException: _LOGGER.exception("Error communicating with Tahoma API") return False try: api.get_setup() devices = api.get_devices() except RequestException: _LOGGER.exception("Cannot fetch informations from Tahoma API") return False hass.data[DOMAIN] = {'controller': api, 'devices': defaultdict(list)} for device in devices: _device = api.get_device(device) if all(ext not in _device.type for ext in exclude): device_type = map_tahoma_device(_device) if device_type is None: continue hass.data[DOMAIN]['devices'][device_type].append(_device) for component in TAHOMA_COMPONENTS: discovery.load_platform(hass, component, DOMAIN, {}, config) return True
def setup(hass, config): """Activate Tahoma component.""" conf = config[DOMAIN] username = conf.get(CONF_USERNAME) password = conf.get(CONF_PASSWORD) exclude = conf.get(CONF_EXCLUDE) try: api = TahomaApi(username, password) except RequestException: _LOGGER.exception("Error when trying to log in to the Tahoma API") return False try: api.get_setup() devices = api.get_devices() scenes = api.get_action_groups() except RequestException: _LOGGER.exception("Error when getting devices from the Tahoma API") return False hass.data[DOMAIN] = {"controller": api, "devices": defaultdict(list), "scenes": []} for device in devices: _device = api.get_device(device) if all(ext not in _device.type for ext in exclude): if is_officially_supported(_device): _LOGGER.info( "Type %s for Tahoma device %s is officially supported", _device.type, _device.label, ) else: device_type = map_tahoma_device(_device) if device_type is None: _LOGGER.warning( "Unsupported type %s for Tahoma device %s", _device.type, _device.label, ) continue hass.data[DOMAIN]["devices"][device_type].append(_device) for scene in scenes: hass.data[DOMAIN]["scenes"].append(scene) for component in TAHOMA_COMPONENTS: discovery.load_platform(hass, component, DOMAIN, {}, config) return True
def setup(opp, config): """Set up Tahoma integration.""" conf = config[DOMAIN] username = conf.get(CONF_USERNAME) password = conf.get(CONF_PASSWORD) exclude = conf.get(CONF_EXCLUDE) try: api = TahomaApi(username, password) except RequestException: _LOGGER.exception("Error when trying to log in to the Tahoma API") return False try: api.get_setup() devices = api.get_devices() scenes = api.get_action_groups() except RequestException: _LOGGER.exception("Error when getting devices from the Tahoma API") return False opp.data[DOMAIN] = { "controller": api, "devices": defaultdict(list), "scenes": [] } for device in devices: _device = api.get_device(device) if all(ext not in _device.type for ext in exclude): device_type = map_tahoma_device(_device) if device_type is None: _LOGGER.warning( "Unsupported type %s for Tahoma device %s", _device.type, _device.label, ) continue opp.data[DOMAIN]["devices"][device_type].append(_device) for scene in scenes: opp.data[DOMAIN]["scenes"].append(scene) for platform in PLATFORMS: discovery.load_platform(opp, platform, DOMAIN, {}, config) return True
import json from tahoma_api import TahomaApi, Action # From the Tahoma HA platform def apply_action(controller, cmd_name, dev_url, *args): """Apply Action to Device.""" action = Action(dev_url) action.add_command(cmd_name, *args) controller.apply_actions('Test', [action]) creds = open('.tahoma.credentials').read() creds = json.loads(creds) print('Logging in to Tahomalink') tahoma = TahomaApi(creds['USERNAME'], creds['PASSWORD']) tahoma.get_setup() print('Get all registered devices') devurlbylabel = {} devs = tahoma.get_devices() for d in devs: _dev = tahoma.get_device(d) devurlbylabel[_dev.label] = _dev.url # print info print('Device label = %s, type = %s (url = %s)' % (_dev.label, _dev.type, _dev.url)) print(' commands = %s' % _dev.command_definitions) try: print(' state = %s' % _dev.active_states) except AttributeError:
#!flask/bin/python from tahoma_api import TahomaApi from tahoma_api import Action from flask import Flask, jsonify import json # Read login data with open("login_data.json") as login_data: login = json.load(login_data) app = Flask(__name__) api = TahomaApi(login["userName"], login["userPassword"]) api.get_setup() devices = api.get_devices() for deviceURL, value in devices.items(): print(deviceURL, value.label, value.command_definitions) @app.route('/execute/<string:label>/<string:command>', methods=['GET']) def execute(label, command): data = { "commands": [ { "name": command, } ] } for deviceURL, value in devices.items():