Ejemplo n.º 1
0
    def __init__(self):
        # discover thermostat in WLAN

        device = broadlink.hysen(('192.168.178.9', 80), '780F77D422D7', 0x4ead)
        device.auth()
        self.__thermostat = device
        ''' # does not work anymore with python 3.8 ???
Ejemplo n.º 2
0
def readSettings(settingsFile, devname):
    try:
        Dev = devices.Dev[devname]
        if Dev['Type'] == 'RM' or Dev['Type'] == 'RM2':
            device = broadlink.rm((Dev['IPAddress'], 80), Dev['MACAddress'],
                                  Dev['Device'])
        elif Dev['Type'] == 'MP1':
            device = broadlink.mp1((Dev['IPAddress'], 80), Dev['MACAddress'],
                                   Dev['Device'])
        elif Dev['Type'] == 'SP1':
            device = broadlink.sp1((Dev['IPAddress'], 80), Dev['MACAddress'],
                                   Dev['Device'])
        elif Dev['Type'] == 'SP2':
            device = broadlink.sp2((Dev['IPAddress'], 80), Dev['MACAddress'],
                                   Dev['Device'])
        elif Dev['Type'] == 'A1':
            device = broadlink.a1((Dev['IPAddress'], 80), Dev['MACAddress'],
                                  Dev['Device'])
        elif Dev['Type'] == 'HYSEN':
            device = broadlink.hysen((Dev['IPAddress'], 80), Dev['MACAddress'],
                                     Dev['Device'])
        elif Dev['Type'] == 'S1C':
            device = broadlink.S1C((Dev['IPAddress'], 80), Dev['MACAddress'],
                                   Dev['Device'])
        elif Dev['Type'] == 'DOOYA':
            device = broadlink.dooya((Dev['IPAddress'], 80), Dev['MACAddress'],
                                     Dev['Device'])
        else:
            return False
        Dev['BaseType'] = "broadlink"

        if 'Delay' in Dev:
            device.delay = Dev['Delay']
        else:
            device.delay = 0.0

        #- set the callbacks
        Dev['learnCommand'] = learnCommand
        Dev['sendCommand'] = sendCommand
        Dev['getStatus'] = None
        Dev['setStatus'] = None
        Dev['getSensor'] = getSensor
        return device
    except Exception as e:
        logfile(
            "Broadlink device support requires broadlink python module.\npip3 install broadlink",
            "WARN")
        return None
Ejemplo n.º 3
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the Broadlink Hysen Climate platform."""
    name = config.get(CONF_NAME)
    ip_addr = config.get(CONF_HOST)
    mac_addr = binascii.unhexlify(config.get(CONF_MAC).encode().replace(b':', b''))
    target_temp_default = config.get(CONF_TARGET_TEMP)
    target_temp_step = config.get(CONF_TARGET_TEMP_STEP)
    operation_list =  DEFAULT_OPERATION_LIST
    
    import broadlink
    
    broadlink_device = broadlink.hysen((ip_addr, 80), mac_addr, None)
    broadlink_device.timeout = config.get(CONF_TIMEOUT)

    try:
        broadlink_device.auth()
        add_devices([
                    BroadlinkHysenClimate(hass, name, broadlink_device, target_temp_default, target_temp_step, operation_list)
                    ])
    except socket.timeout:
        _LOGGER.error("Failed to connect to Broadlink Hysen Device IP:%s",ip_addr)
Ejemplo n.º 4
0
cursor = db.cursor()
cursor.execute('''
    CREATE TABLE IF NOT EXISTS events(id INTEGER PRIMARY KEY, action TEXT, desired_temp REAL, current_temp REAL, created_at DATE)
''')

db.commit()

# other stuff:
strType = '0x4ead'  #HYSEN THERMOSTAT TYPE

#convert mac string
macbytes = bytearray.fromhex(strMac.replace(':', ''))

#get the broadlink hysen device
device = broadlink.hysen((strHost, 80), macbytes, strType)

# get auth for futher comunications
device.auth()

now = datetime.utcnow()
# do wathever you want with data :)
data = device.get_full_status()
# print(json.dumps(data, separators=(',', ':')))
print("%s Power %d - Fire %d. Current temp: %f VS desired %f." %
      (now, data['power'], data['active'], data['room_temp'],
       data['thermostat_temp']))

if (data['power'] == 1):

    cursor.execute(
Ejemplo n.º 5
0
def readSettingsFile():
    global devices
    global DeviceByName
    global RestrictAccess
    global LearnFrom
    global OverwriteProtected
    global GlobalPassword
    global GlobalTimeout
    global settingsFile

    # A few defaults
    serverPort = 8080
    Autodetect = False
    OverwriteProtected = True
    listen_address = '0.0.0.0'
    broadcast_address = '255.255.255.255'

    settingsFile = configparser.ConfigParser()
    settingsFile.optionxform = str
    settingsFile.read(settings.settingsINI)

    Dev = settings.Dev
    GlobalTimeout = settings.GlobalTimeout
    DiscoverTimeout = settings.DiscoverTimeout

    # Override them
    if settingsFile.has_option('General', 'password'):
        GlobalPassword = settingsFile.get('General', 'password').strip()

    if settingsFile.has_option('General', 'serverPort'):
        serverPort = int(settingsFile.get('General', 'serverPort'))

    if settingsFile.has_option('General', 'serverAddress'):
        listen_address = settingsFile.get('General', 'serverAddress')
        if listen_address.strip() == '':
            listen_address = '0.0.0.0'

    if settingsFile.has_option('General', 'restrictAccess'):
        RestrictAccess = settingsFile.get('General', 'restrictAccess').strip()

    if settingsFile.has_option('General', 'learnFrom'):
        LearnFrom = settingsFile.get('General', 'learnFrom').strip()

    if settingsFile.has_option('General', 'allowOverwrite'):
        OverwriteProtected = False

    if settingsFile.has_option('General', 'broadcastAddress'):
        broadcast = settingsFile.get('General', 'broadcastAddress')
        if broadcast_address.strip() == '':
            broadcast_address = '255.255.255.255'

    if settingsFile.has_option('General', 'Autodetect'):
        try:
            DiscoverTimeout = int(
                settingsFile.get('General', 'Autodetect').strip())
        except:
            DiscoverTimeout = 5
        Autodetect = True
        settingsFile.remove_option('General', 'Autodetect')

    # Device list
    DeviceByName = {}
    if not settings.DevList:
        Autodetect = True

    if Autodetect == True:
        print("Beginning device auto-detection ... ")
        # Try to support multi-homed broadcast better
        try:
            devices = broadlink.discover(DiscoverTimeout, listen_address,
                                         broadcast_address)
        except:
            devices = broadlink.discover(DiscoverTimeout, listen_address)

        backupSettings()
        try:
            broadlinkControlIniFile = open(
                path.join(settings.applicationDir, 'settings.ini'), 'w')
            for device in devices:
                try:
                    device.hostname = socket.gethostbyaddr(device.host[0])[0]
                    if "." in device.hostname:
                        device.hostname = device.hostname.split('.')[0]
                except:
                    device.hostname = "Broadlink" + device.type.upper()
                if device.hostname in DeviceByName:
                    device.hostname = "%s-%s" % (
                        device.hostname, str(device.host).split('.')[3])
                DeviceByName[device.hostname] = device
                if not settingsFile.has_section(device.hostname):
                    settingsFile.add_section(device.hostname)
                settingsFile.set(device.hostname, 'IPAddress',
                                 str(device.host[0]))
                hexmac = ':'.join(["%02x" % (x) for x in reversed(device.mac)])
                settingsFile.set(device.hostname, 'MACAddress', hexmac)
                settingsFile.set(device.hostname, 'Device',
                                 hex(device.devtype))
                settingsFile.set(device.hostname, 'Timeout',
                                 str(device.timeout))
                settingsFile.set(device.hostname, 'Type', device.type.upper())
                device.auth()
                print("%s: Found %s on %s (%s) type: %s" %
                      (device.hostname, device.type, device.host, hexmac,
                       hex(device.devtype)))
            settingsFile.write(broadlinkControlIniFile)
            broadlinkControlIniFile.close()
        except StandardError as e:
            print("Error writing settings file: %s" % e)
            restoreSettings()
    else:
        devices = []
    if settings.DevList:
        for devname in settings.DevList:
            if Dev[devname, 'Type'] == 'RM' or Dev[devname, 'Type'] == 'RM2':
                device = broadlink.rm((Dev[devname, 'IPAddress'], 80),
                                      Dev[devname, 'MACAddress'],
                                      Dev[devname, 'Device'])
            if Dev[devname, 'Type'] == 'MP1':
                device = broadlink.mp1((Dev[devname, 'IPAddress'], 80),
                                       Dev[devname, 'MACAddress'],
                                       Dev[devname, 'Device'])
            if Dev[devname, 'Type'] == 'SP1':
                device = broadlink.sp1((Dev[devname, 'IPAddress'], 80),
                                       Dev[devname, 'MACAddress'],
                                       Dev[devname, 'Device'])
            if Dev[devname, 'Type'] == 'SP2':
                device = broadlink.sp2((Dev[devname, 'IPAddress'], 80),
                                       Dev[devname, 'MACAddress'],
                                       Dev[devname, 'Device'])
            if Dev[devname, 'Type'] == 'A1':
                device = broadlink.a1((Dev[devname, 'IPAddress'], 80),
                                      Dev[devname, 'MACAddress'],
                                      Dev[devname, 'Device'])
            if Dev[devname, 'Type'] == 'HYSEN':
                device = broadlink.hysen((Dev[devname, 'IPAddress'], 80),
                                         Dev[devname, 'MACAddress'],
                                         Dev[devname, 'Device'])
            if Dev[devname, 'Type'] == 'S1C':
                device = broadlink.S1C((Dev[devname, 'IPAddress'], 80),
                                       Dev[devname, 'MACAddress'],
                                       Dev[devname, 'Device'])
            if Dev[devname, 'Type'] == 'DOOYA':
                device = broadlink.dooya((Dev[devname, 'IPAddress'], 80),
                                         Dev[devname, 'MACAddress'],
                                         Dev[devname, 'Device'])
            device.timeout = Dev[devname, 'Timeout']
            if not devname in DeviceByName:
                device.hostname = devname
                device.auth()
                devices.append(device)
                print("%s: Read %s on %s (%s)" %
                      (devname, device.type, str(device.host[0]), device.mac))
            DeviceByName[devname] = device
    return {
        "port": serverPort,
        "listen": listen_address,
        "timeout": GlobalTimeout
    }