Beispiel #1
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the Awesome heater platform."""

    # Assign configuration variables. The configuration check takes care they are
    # present.
    host = config.get(CONF_HOST)
    ip = config.get(CONF_IP_ADDRESS)

    # Setup connection with devices/cloud
    if ip == 'discover':
        _LOGGER.info("discovering and connecting to %s", host)
        hub = nobo(serial=host)
    else:
        _LOGGER.info("connecting to %s:%s", ip, host)
        hub = nobo(serial=host, ip=ip, discover=False)

    # Verify that passed in configuration works


#    if not hub.is_valid_login():
#        _LOGGER.error("Could not connect to AwesomeHeater hub")
#        return False

# Add devices
    hub.socket_received_all_info.wait()
    add_devices(AwesomeHeater(zones, hub) for zones in hub.zones)
    _LOGGER.info("component is up and running on %s:%s", hub.hub_ip,
                 hub.hub_serial)

    return True
Beispiel #2
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the Awesome heater platform."""

    # Assign configuration variables. The configuration check takes care they are
    # present.
    host = config.get(CONF_HOST)
    ip = config.get(CONF_IP_ADDRESS)

    # Setup connection with devices/cloud
    if ip == 'discover':
        _LOGGER.info("discovering and connecting to %s", host)
        hub = nobo(serial=host)
    else:
        _LOGGER.info("connecting to %s:%s", ip, host)
        hub = nobo(serial=host, ip=ip, discover=False)

    # Verify that passed in configuration works


#    if not hub.is_valid_login():
#        _LOGGER.error("Could not connect to AwesomeHeater hub")
#        return False

# Find OFF command (week profile) to use for all zones:
    command_off_name = config.get(CONF_COMMAND_OFF)
    command_on_by_id = {}  # By default, nothing can be turned on
    if command_off_name == '':
        _LOGGER.info(
            "Not possible to turn off (or on) any heater, because OFF week profile was not specified"
        )
        command_off_id = None
    else:
        command_off_id = get_id_from_name(command_off_name, hub.week_profiles)
        if command_off_id == '' or command_off_id == None:
            _LOGGER.error(
                "Can not turn off (or on) any heater, because week profile '%s' was not found",
                command_off_name)
        else:
            _LOGGER.info(
                "To turn off any heater, week profile %s '%s' will be used",
                command_off_id, command_off_name)

            # Find ON command (week profile) for the different zones:
            command_on_dict = config.get(CONF_COMMAND_ON)
            command_on_by_id = {}
            if command_on_dict.keys().__len__ == 0:
                _LOGGER.info(
                    "Not possible to turn on any heater, because ON week profile was not specified"
                )
            for room_name in command_on_dict.keys():
                command_on_name = command_on_dict[room_name]
                room_id = get_id_from_name(room_name, hub.zones)
                if room_id == '' or room_id == None:
                    _LOGGER.error(
                        "Can not turn on (or off) heater in zone '%s', because that zone (heater name) was not found",
                        room_name)
                else:
                    command_on_id = get_id_from_name(command_on_name,
                                                     hub.week_profiles)
                    if command_on_id == '' or command_on_id == None:
                        _LOGGER.error(
                            "Can not turn on (or off) heater in zone '%s', because week profile '%s' was not found",
                            room_name, command_on_name)
                    else:
                        _LOGGER.info(
                            "To turn on heater %s '%s', week profile %s '%s' will be used",
                            room_id, room_name, command_on_id, command_on_name)
                        command_on_by_id[room_id] = command_on_id

    # Add devices
    hub.socket_received_all_info.wait()
    add_devices(
        AwesomeHeater(zones, hub, command_off_id, command_on_by_id.get(zones))
        for zones in hub.zones)
    _LOGGER.info("component is up and running on %s:%s", hub.hub_ip,
                 hub.hub_serial)

    return True
Beispiel #3
0
from pynobo import nobo
from flask import Flask, abort, request
import os
app = Flask(__name__)

MAX_TEMPERATURE = 25
MIN_TEMPERATURE = 8

hub = nobo(os.environ['NOBO_ID'])


@app.route('/<zoneId>')
def root(zoneId):
    return {
        "comfortTemperature": int(hub.zones[zoneId]['temp_comfort_c']),
        "ecoTemperature": int(hub.zones[zoneId]['temp_eco_c']),
        "mode": hub.get_current_zone_mode(zoneId)
    }


@app.route('/update', methods=['POST'])
def update():
    content = request.json
    zoneId = content['zoneId']
    comfortTemperature = int(content['comfortTemperature'])
    ecoTemperature = int(content['ecoTemperature'])
    mode = content['mode']

    if comfortTemperature < MIN_TEMPERATURE or comfortTemperature > MAX_TEMPERATURE:
        return abort(400)