Exemplo n.º 1
0
def getAog(device):
    getSettings()
    domain = AogGetDomain(device)
    if domain == None:
        return None

    aog = AogState()
    aog.name = device["Name"]  #.encode('ascii', 'ignore')
    aog.domain = domain
    aog.id = device["idx"]
    aog.entity_id = domain + aog.id
    aog.state = device.get("Data", "Scene")
    aog.level = device.get("LevelInt", 0)
    aog.temp = device.get("Temp")
    aog.humidity = device.get("Humidity")
    aog.setpoint = device.get("SetPoint")
    aog.color = device.get("Color")
    aog.protected = device.get("Protected")
    aog.maxdimlevel = device.get("MaxDimLevel")
    aog.seccode = settings.get("SecPassword")
    aog.tempunit = settings.get("TempUnit")
    aog.battery = device.get("BatteryLevel")

    if lightDOMAIN == aog.domain and "Dimmer" == device["SwitchType"]:
        aog.attributes = ATTRS_BRIGHTNESS
    if outletDOMAIN == aog.domain and "Dimmer" == device["SwitchType"]:
        aog.attributes = ATTRS_BRIGHTNESS
    if colorDOMAIN == aog.domain and "Dimmer" == device["SwitchType"]:
        aog.attributes = ATTRS_BRIGHTNESS
    if colorDOMAIN == aog.domain and "RGBWW" == device["SubType"]:
        aog.attributes = ATTRS_COLOR_TEMP
    if climateDOMAIN == aog.domain and "Thermostat" == device["Type"]:
        aog.attributes = ATTRS_THERMSTATSETPOINT
    if blindsDOMAIN == aog.domain and "Blinds Percentage" == device[
            "SwitchType"]:
        aog.attributes = ATTRS_PERCENTAGE
    if blindsDOMAIN == aog.domain and "Blinds Percentage Inverted" == device[
            "SwitchType"]:
        aog.attributes = ATTRS_PERCENTAGE

    # Try to get device specific voice control configuration from Domoticz first
    # Read it from the configuration file if not in Domoticz (for backward compatibility)
    desc = getDeviceConfig(device.get("Description"))
    if desc == None:
        desc = getDesc(aog)

    if desc != None:
        n = desc.get('nicknames', None)
        if n != None:
            print(aog.name, 'nicknames:', n)
            aog.nicknames = n
        r = desc.get('room', None)
        if r != None:
            print(aog.name, 'room:', r)
            aog.room = r
        ack = desc.get('ack', False)
        if ack:
            print(aog.name, 'ack:', ack)
            aog.ack = ack
    return aog
Exemplo n.º 2
0
def getAog(device):
    getSettings()
    domain = AogGetDomain(device)
    if domain == None:
        return None

    aog = AogState()
    aog.name = device["Name"]  #.encode('ascii', 'ignore')
    aog.domain = domain
    aog.id = device["idx"]
    aog.entity_id = domain + aog.id
    aog.state = device.get("Data", "Scene")
    aog.level = device.get("LevelInt", 0)
    aog.temp = device.get("Temp")
    aog.humidity = device.get("Humidity")
    aog.setpoint = device.get("SetPoint")
    aog.color = device.get("Color")
    aog.protected = device.get("Protected")
    aog.maxdimlevel = device.get("MaxDimLevel")
    aog.seccode = settings.get("SecPassword")
    aog.tempunit = settings.get("TempUnit")
    aog.battery = device.get("BatteryLevel")
    aog.camera = device.get("CameraIdx")
    aog.cameras = cameras

    if lightDOMAIN == aog.domain and "Dimmer" == device["SwitchType"]:
        aog.attributes = ATTRS_BRIGHTNESS
    if outletDOMAIN == aog.domain and "Dimmer" == device["SwitchType"]:
        aog.attributes = ATTRS_BRIGHTNESS
    if colorDOMAIN == aog.domain and "Dimmer" == device["SwitchType"]:
        aog.attributes = ATTRS_BRIGHTNESS
    if colorDOMAIN == aog.domain and "RGBWW" == device["SubType"]:
        aog.attributes = ATTRS_COLOR_TEMP
    if climateDOMAIN == aog.domain and "Thermostat" == device["Type"]:
        aog.attributes = ATTRS_THERMSTATSETPOINT
    if blindsDOMAIN == aog.domain and "Blinds Percentage" == device[
            "SwitchType"]:
        aog.attributes = ATTRS_PERCENTAGE
    if blindsDOMAIN == aog.domain and "Blinds Percentage Inverted" == device[
            "SwitchType"]:
        aog.attributes = ATTRS_PERCENTAGE
    if cameraDOMAIN == aog.domain:
        getCameras(aog.entity_id, aog.camera)

    desc = getDesc(aog)

    if desc != None:
        n = desc.get('nicknames', None)
        if n != None:
            aog.nicknames = n
        r = desc.get('room', None)
        if r != None:
            aog.room = r
    return aog
Exemplo n.º 3
0
def getAog(device):
    domain = AogGetDomain(device)
    if domain is None:
        return None

    aog = AogState()
    aog.name = device["Name"]  # .encode('ascii', 'ignore')
    aog.domain = domain
    aog.id = device["idx"]
    aog.entity_id = domain + aog.id
    aog.plan = device.get("PlanID")                               
    aog.state = device.get("Data", "Scene")
    aog.level = device.get("LevelInt", 0)
    aog.temp = device.get("Temp")
    aog.humidity = device.get("Humidity")
    aog.setpoint = device.get("SetPoint")
    if aog.domain is "Color":
        aog.color = device.get("Color")
    aog.protected = device.get("Protected")
    aog.maxdimlevel = device.get("MaxDimLevel")   
    aog.battery = device.get("BatteryLevel")
    aog.hardware = device.get("HardwareName")
    aog.selectorLevelName = device.get("LevelNames")
    aog.lastupdate = device.get("LastUpdate")
    
    aog.language = settings.get("Language")
    aog.tempunit = settings.get("TempUnit")
    if aog.domain is "Security":
        aog.seccode = settings.get("SecPassword")
        aog.secondelay = settings.get("SecOnDelay")


    # Try to get device specific voice control configuration from Domoticz
    # Read it from the configuration file if not in Domoticz (for backward compatibility)
    desc = getDeviceConfig(device.get("Description"))
    if desc is not None:
        logger.debug('<voicecontrol> tags found for idx %s in domoticz description.', aog.id)
        logger.debug('Device_Config for idx %s will be ignored in config.yaml!', aog.id)
    if desc is None:
        desc = getDesc(aog)

    if desc is not None:
        dt = desc.get('devicetype', None)
        if dt is not None:
            if aog.domain in [domains['blinds']]:
                if dt.lower() in ['window', 'gate', 'garage', 'door']:
                    aog.domain = domains[dt.lower()]
            if aog.domain in [domains['light'], domains['switch']]:
                if dt.lower() in ['window', 'door', 'gate', 'garage', 'light', 'ac_unit', 'bathtub', 'coffeemaker', 'dishwasher', 'dryer', 'fan', 'heater', 'kettle', 'media', 'microwave', 'outlet', 'oven', 'speaker', 'switch', 'vacuum', 'washer', 'waterheater']:
                    aog.domain = domains[dt.lower()]
            if aog.domain in [domains['door']]:
                if dt.lower() in ['window', 'gate', 'garage']:
                    aog.domain = domains[dt.lower()]    
            if aog.domain in [domains['selector']]:
                if dt.lower() in ['vacuum']:
                    aog.domain = domains[dt.lower()]
        pn = desc.get('name', None)
        if pn is not None:
            aog.name = pn
        n = desc.get('nicknames', None)
        if n is not None:
            aog.nicknames = n
        r = desc.get('room', None)
        if r is not None:
            aog.room = r
        ack = desc.get('ack', False)
        if ack:
            aog.ack = ack
        report_state = desc.get('report_state', True)
        if not ReportState.enable_report_state():
            aog.report_state = False
        if not report_state:
            aog.report_state = report_state            
        if domains['thermostat'] == aog.domain:
            at_idx = desc.get('actual_temp_idx', None)
            if at_idx is not None:
                aog.actual_temp_idx = at_idx
                try:
                    aog.state = str(aogDevs[domains['temperature'] + at_idx].temp)
                    aogDevs[domains['temperature'] + at_idx].domain = domains['merged'] + aog.id + ')'
                except:
                    logger.error('Merge Error, Cant find temperature device with idx %s', at_idx)
            modes_idx = desc.get('selector_modes_idx', None)
            if modes_idx is not None:
                aog.modes_idx = modes_idx
                try:
                    aog.level = aogDevs[domains['selector'] + modes_idx].level
                    aog.selectorLevelName = aogDevs[domains['selector'] + modes_idx].selectorLevelName
                    aogDevs[domains['selector'] + modes_idx].domain = domains['merged'] + aog.id + ')'
                except:
                    logger.error('Merge Error, Cant find selector device with idx %s', modes_idx)
        if aog.domain in [domains['heater'], domains['kettle'], domains['waterheater'], domains['oven']]:
            tc_idx = desc.get('merge_thermo_idx', None)
            if tc_idx is not None:
                aog.merge_thermo_idx = tc_idx
                try:
                    aog.temp = aogDevs[domains['thermostat'] + tc_idx].state
                    aog.setpoint = aogDevs[domains['thermostat'] + tc_idx].setpoint
                    aogDevs[domains['thermostat'] + tc_idx].domain = domains['merged'] + aog.id + ')'
                except:
                    logger.error('Merge Error, Cant find thermostat device with idx %s', tc_idx)
        hide = desc.get('hide', False)
        if hide:
            if aog.domain not in [domains['scene'], domains['group']]:
                aog.domain = domains['hidden']
            else:
                logger.error('Scenes and Groups does not support function "hide" yet')
            
    if aog.domain in [domains['camera']]:
        aog.report_state = False
        
    if domains['light'] == aog.domain and "Dimmer" == device["SwitchType"]:
        aog.attributes = ATTRS_BRIGHTNESS
    if domains['fan'] == aog.domain and "Selector" == device["SwitchType"]:
        aog.attributes = ATTRS_FANSPEED
    if domains['outlet'] == aog.domain and "Dimmer" == device["SwitchType"]:
        aog.attributes = ATTRS_BRIGHTNESS
    if domains['color'] == aog.domain and "Dimmer" == device["SwitchType"]:
        aog.attributes = ATTRS_BRIGHTNESS
    if domains['color'] == aog.domain and device["SubType"] in ["RGBWW", "White"]:
        aog.attributes = ATTRS_COLOR_TEMP
    if domains['thermostat'] == aog.domain and "Thermostat" == device["Type"]:
        aog.attributes = ATTRS_THERMSTATSETPOINT
    if domains['blinds'] == aog.domain and "Blinds Percentage" == device["SwitchType"]:
        aog.attributes = ATTRS_PERCENTAGE
    if domains['blindsinv'] == aog.domain and "Blinds Percentage Inverted" == device["SwitchType"]:
        aog.attributes = ATTRS_PERCENTAGE
    if domains['vacuum'] == aog.domain and "Selector" == device["SwitchType"]:
        aog.attributes = ATTRS_VACUUM_MODES
        
    if aog.room == None:
        if aog.domain not in [domains['scene'], domains['group']]:
            if aog.plan is not "0":
                aog.room = getPlans(aog.plan)
        
    return aog