Exemplo n.º 1
0
    def __init__(self, _mac, _name):
        """Initialize the thermostat."""
        # we want to avoid name clash with this module..
        import eq3bt as eq3

        self.modes = {
            None:
            STATE_UNKNOWN,  # When not yet connected.
            eq3.Mode.Unknown:
            STATE_UNKNOWN,
            eq3.Mode.Auto:
            STATE_AUTO,
            # away handled separately, here just for reverse mapping
            eq3.Mode.Away:
            STATE_AWAY,
            eq3.Mode.Closed:
            STATE_OFF,
            eq3.Mode.Open:
            STATE_ON,
            eq3.Mode.Manual:
            STATE_MANUAL,
            eq3.Mode.Boost:
            STATE_BOOST
        }

        self.reverse_modes = {v: k for k, v in self.modes.items()}

        self._name = _name
        self._thermostat = eq3.Thermostat(_mac)
Exemplo n.º 2
0
def register(room_id):
    if g.user['usertype_fk'] != 1:
        response = make_response(
            "You don't have permission to register a heater", 401)
        return reponse
    db = get_db()
    if request.method == 'POST':
        error = None
        mac = request.form['mac']
        name = request.form['name']
        room_id = request.form['room_id']
        if not name:
            error = "You have to give the heater a name"
        if db.execute("SELECT * FROM heater WHERE name = ?;",
                      (name, )).fetchone() is not None:
            error = "This heater is already registered"
        if error is None:
            cur = db.execute(
                "INSERT INTO heater(mac, name, room_fk) VALUES(?, ?, ?);",
                (mac, name, room_id))
            db.commit()
            return redirect(url_for('room.view', room_id=room_id))
    rooms = db.execute("SELECT * FROM room;").fetchall()
    room = db.execute("SELECT * FROM room WHERE id = ?;",
                      (room_id, )).fetchone()
    # Scan for thermostats, try to get current status
    service = DiscoveryService()
    devices = service.discover(5)
    macs = [mac for mac in devices if devices[mac] == 'CC-RT-BLE']
    db = get_db()
    heaters = []
    for mac in macs:
        h = {}
        h['mac'] = mac
        heater = db.execute(
            "SELECT h.name, r.name as room FROM heater h JOIN room r ON h.room_fk = r.id WHERE h.mac = ?;",
            (mac, )).fetchone()
        if heater is not None:
            h['status'] = 'registered'
            h['name'] = heater['name']
            h['assigned_to'] = heater['room']
        else:
            h['status'] = 'unassigned'
        t = eq3bt.Thermostat(mac)
        try:
            t.update()
            h['target_temp'] = t.target_temperature
            h['mode'] = t.mode_readable
        except BTLEDisconnectError as e:
            print(f"Unable to connect to thermostat: {mac}")
        heaters.append(h)
    return render_template('heater/register.html',
                           rooms=rooms,
                           room=room,
                           heaters=heaters)
Exemplo n.º 3
0
    def __init__(self, _mac, _name):
        """Initialize the thermostat."""
        # we want to avoid name clash with this module..
        import eq3bt as eq3

        self.modes = {eq3.Mode.Open: STATE_ON,
                      eq3.Mode.Closed: STATE_OFF,
                      eq3.Mode.Auto: STATE_AUTO,
                      eq3.Mode.Manual: STATE_MANUAL,
                      eq3.Mode.Boost: STATE_BOOST,
                      eq3.Mode.Away: STATE_AWAY}

        self.reverse_modes = {v: k for k, v in self.modes.items()}

        self._name = _name
        self._thermostat = eq3.Thermostat(_mac)
Exemplo n.º 4
0
    def __init__(self, _mac, _name):
        """Initialize the thermostat."""
        # We want to avoid name clash with this module.
        import eq3bt as eq3  # pylint: disable=import-error

        self.modes = {
            eq3.Mode.Open: STATE_ON,
            eq3.Mode.Closed: STATE_OFF,
            eq3.Mode.Auto: STATE_HEAT,
            eq3.Mode.Manual: STATE_MANUAL,
            eq3.Mode.Boost: STATE_BOOST,
            eq3.Mode.Away: STATE_ECO,
        }

        self.reverse_modes = {v: k for k, v in self.modes.items()}

        self._name = _name
        self._thermostat = eq3.Thermostat(_mac)
        self._target_temperature = None
        self._target_mode = None
Exemplo n.º 5
0
 def __init__(self, _mac, _name):
     """Initialize the thermostat."""
     # We want to avoid name clash with this module.
     self._name = _name
     self._thermostat = eq3.Thermostat(_mac)
Exemplo n.º 6
0
 def __init__(self, mac: str, name: str) -> None:
     """Initialize the thermostat."""
     # We want to avoid name clash with this module.
     self._attr_name = name
     self._attr_unique_id = format_mac(mac)
     self._thermostat = eq3.Thermostat(mac)
Exemplo n.º 7
0
Arquivo: eq3.py Projeto: mauzr/snake
 def setup(self):
     self.thermostat = eq3bt.Thermostat(self.mac)
     yield
     self.thermostat = None