当前位置: 首页>>代码示例>>Python>>正文


Python config_validation.string方法代码示例

本文整理汇总了Python中homeassistant.helpers.config_validation.string方法的典型用法代码示例。如果您正苦于以下问题:Python config_validation.string方法的具体用法?Python config_validation.string怎么用?Python config_validation.string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在homeassistant.helpers.config_validation的用法示例。


在下文中一共展示了config_validation.string方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_operation

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import string [as 别名]
def get_operation(self,ui_operation = None, task = None):
        """ transform operation string between ui and task"""
        if ui_operation is not None:
            # _LOGGER.debug("get_operation from ui:{}|{}".format(ui_operation,self._dic_operation.get(ui_operation.split(' ')[0])))
            return self._dic_operation_cn_to_en.get(ui_operation.split(' ')[0])
        if task is not None:
            if 'custom:' in task['operation']:
                return '调服务'
            if task['operation'] in ['on','off']:
                # _LOGGER.debug("get_operation from task:{}|{}".format(task['operation'],self._dic_operation.get(task['operation'])))
                return self._dic_operation_en_to_cn.get(task['operation'])
            else:
                # _LOGGER.debug("get_operation from task:{}|{}".format(task['operation'],'{} [1:{}]'.format(self._dic_operation.get(task['operation']),task['ratio'])))
                return '{} [1:{}]'.format(self._dic_operation_en_to_cn.get(task['operation']),task['ratio'])
        else:
            return '关' 
开发者ID:cnk700i,项目名称:common_timer,代码行数:18,代码来源:__init__.py

示例2: on_open

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import string [as 别名]
def on_open(self, *args):
        self.connected = True
        self.last_update = time.time()

        payload = {
            'action'    : "userOnline",
            'userAgent' : 'app',
            'version'   : 6,
            'nonce'     : ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(8)),
            'apkVersion': "1.8",
            'os'        : 'iOS',
            'at'        : self._sonoff.get_bearer_token(),
            'apikey'    : self._sonoff.get_user_apikey(),
            'ts'        : str(int(time.time())),
            'model'     : self._sonoff.get_model(),
            'romVersion': self._sonoff.get_romVersion(),
            'sequence'  : str(time.time()).replace('.','')
        }

        self.send(json.dumps(payload)) 
开发者ID:peterbuga,项目名称:HASS-sonoff-ewelink,代码行数:22,代码来源:__init__.py

示例3: calculate_crc16

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import string [as 别名]
def calculate_crc16(self, input_data):
        from ctypes import c_ushort
        crc16_tab = []
        crc16_constant = 0xA001

        for i in range(0, 256):
            crc = c_ushort(i).value
            for j in range(0, 8):
                if (crc & 0x0001):
                    crc = c_ushort(crc >> 1).value ^ crc16_constant
                else:
                    crc = c_ushort(crc >> 1).value
            crc16_tab.append(hex(crc))

        try:
            is_string = isinstance(input_data, str)
            is_bytes = isinstance(input_data, bytes)

            if not is_string and not is_bytes:
                raise Exception("Please provide a string or a byte sequence "
                                "as argument for calculation.")

            crcValue = 0xffff

            for c in input_data:
                d = ord(c) if is_string else c
                tmp = crcValue ^ d
                rotated = c_ushort(crcValue >> 8).value
                crcValue = rotated ^ int(crc16_tab[(tmp & 0x00ff)], 0)

            return crcValue
        except Exception as e:
            print("EXCEPTION(calculate): {}".format(e)) 
开发者ID:mairas,项目名称:hysen,代码行数:35,代码来源:climate.py

示例4: _url_encode

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import string [as 别名]
def _url_encode(string):
        string_decoded_encoded = urllib.parse.quote(urllib.parse.unquote(string))
        if string_decoded_encoded != string:
            string = string_decoded_encoded
        return string 
开发者ID:eyesoft,项目名称:home-assistant-custom-components,代码行数:7,代码来源:__init__.py

示例5: create_parameters1cv

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import string [as 别名]
def create_parameters1cv(options):
    # Panel settings - can only be set on creation
    return {
        vol.Required(CONF_LANGUAGE,         default=create_default(options, CONF_LANGUAGE, "EN") )         : cv.string,
        vol.Optional(CONF_EXCLUDE_SENSOR,   default=create_default(options, CONF_EXCLUDE_SENSOR, ""))      : cv.string,
        vol.Optional(CONF_EXCLUDE_X10,      default=create_default(options, CONF_EXCLUDE_X10, ""))         : cv.string,
        vol.Optional(CONF_DOWNLOAD_CODE,    default=create_default(options, CONF_DOWNLOAD_CODE, "") )      : cv.string,
        vol.Optional(CONF_FORCE_STANDARD,   default=create_default(options, CONF_FORCE_STANDARD, False))   : cv.boolean, 
        vol.Optional(CONF_FORCE_AUTOENROLL, default=create_default(options, CONF_FORCE_AUTOENROLL, False)) : cv.boolean, 
        vol.Optional(CONF_AUTO_SYNC_TIME,   default=create_default(options, CONF_AUTO_SYNC_TIME, True))    : cv.boolean
    } 
开发者ID:davesmeghead,项目名称:visonic,代码行数:13,代码来源:create_schema.py

示例6: create_parameters2cv

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import string [as 别名]
def create_parameters2cv(options):
    # Panel settings - can be modified/edited
    return {
        vol.Optional(CONF_MOTION_OFF_DELAY,     default=create_default(options, CONF_MOTION_OFF_DELAY, 120) )      : cv.positive_int,
        vol.Optional(CONF_SIREN_SOUNDING,       default=create_default(options, CONF_SIREN_SOUNDING,["intruder"])) : cv.multi_select(available_siren_values),
        vol.Optional(CONF_OVERRIDE_CODE,        default=create_default(options, CONF_OVERRIDE_CODE, "") )          : cv.string,
        vol.Optional(CONF_ARM_CODE_AUTO,        default=create_default(options, CONF_ARM_CODE_AUTO, False))        : cv.boolean,
        vol.Optional(CONF_FORCE_KEYPAD,         default=create_default(options, CONF_FORCE_KEYPAD, False))         : cv.boolean,
        vol.Optional(CONF_INSTANT_ARM_AWAY,     default=create_default(options, CONF_INSTANT_ARM_AWAY, False))     : cv.boolean,
        vol.Optional(CONF_INSTANT_ARM_HOME,     default=create_default(options, CONF_INSTANT_ARM_HOME, False))     : cv.boolean,
        vol.Optional(CONF_ENABLE_REMOTE_ARM,    default=create_default(options, CONF_ENABLE_REMOTE_ARM, False))    : cv.boolean,
        vol.Optional(CONF_ENABLE_REMOTE_DISARM, default=create_default(options, CONF_ENABLE_REMOTE_DISARM, False)) : cv.boolean,
        vol.Optional(CONF_ENABLE_SENSOR_BYPASS, default=create_default(options, CONF_ENABLE_SENSOR_BYPASS, False)) : cv.boolean
    } 
开发者ID:davesmeghead,项目名称:visonic,代码行数:16,代码来源:create_schema.py

示例7: create_parameters3cv

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import string [as 别名]
def create_parameters3cv(options):
    # Log file parameters
    return {
        vol.Optional(CONF_LOG_EVENT,            default=create_default(options, CONF_LOG_EVENT, False))       : cv.boolean,
        vol.Optional(CONF_LOG_DONE,             default=create_default(options, CONF_LOG_DONE, False))        : cv.boolean,
        vol.Optional(CONF_LOG_REVERSE,          default=create_default(options, CONF_LOG_REVERSE, False))     : cv.boolean,
        vol.Optional(CONF_LOG_CSV_TITLE,        default=create_default(options, CONF_LOG_CSV_TITLE, False))   : cv.boolean,
        vol.Optional(CONF_LOG_XML_FN,           default=create_default(options, CONF_LOG_XML_FN, ""))         : cv.string,
        vol.Optional(CONF_LOG_CSV_FN,           default=create_default(options, CONF_LOG_CSV_FN, ""))         : cv.string,
        vol.Optional(CONF_LOG_MAX_ENTRIES,      default=create_default(options, CONF_LOG_MAX_ENTRIES, 10000)) : cv.positive_int
    } 
开发者ID:davesmeghead,项目名称:visonic,代码行数:13,代码来源:create_schema.py

示例8: convert_string_to_device_name

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import string [as 别名]
def convert_string_to_device_name(name):
    """convert string to device name"""
    try:
        return (ba.hexlify(name.encode(ENCODING_CODEC)) + ((32-len(name))*"00").encode(ENCODING_CODEC)).decode(ENCODING_CODEC)
    except Exception:
        _LOGGER.exception('failed to convert ' + name + ' to device name')
        raise 
开发者ID:TomerFi,项目名称:home-assistant-custom-components,代码行数:9,代码来源:__init__.py

示例9: _get_location_from_attributes

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import string [as 别名]
def _get_location_from_attributes(entity):
        """Get the lat/long string from an entities attributes."""
        attr = entity.attributes
        return "%s,%s" % (attr.get(ATTR_LATITUDE), attr.get(ATTR_LONGITUDE)) 
开发者ID:macbury,项目名称:SmartHouse,代码行数:6,代码来源:sensor.py

示例10: extract_date

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import string [as 别名]
def extract_date(self, raw_data):
    try:
      date = raw_data.select(".kkm-card div:nth-of-type(8) b")[0].string
      d = time.strptime(date, '%Y-%m-%d')
      self._expire_at = datetime(*d[:6])
      self._lines = raw_data.select(".kkm-card div:nth-of-type(10) b")[0].string.split(',')
    except IndexError as error:
      _LOGGER.error("Failed to extract date from page: %s", error) 
开发者ID:macbury,项目名称:SmartHouse,代码行数:10,代码来源:sensor.py

示例11: update_devices

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import string [as 别名]
def update_devices(self):
        if self.get_user_apikey() is None:
            _LOGGER.error("Initial login failed, devices cannot be updated!")
            return self._devices

        # we are in the grace period, no updates to the devices
        if self._skipped_login and self.is_grace_period():
            _LOGGER.info("Grace period active")
            return self._devices

        r = requests.get('https://{}-api.coolkit.cc:8080/api/user/device?lang=en&apiKey={}&getTags=1&version=6&ts=%s&nonce=%s&appid=oeVkj2lYFGnJu5XUtWisfW4utiN4u9Mq&imei=%s&os=iOS&model=%s&romVersion=%s&appVersion=%s'.format(
            self._api_region, self.get_user_apikey(), str(int(time.time())), ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(8)), self._imei, self._model, self._romVersion, self._appVersion
            ), headers=self._headers)

        # _LOGGER.error(r.text)

        resp = r.json()
        if 'error' in resp and resp['error'] in [HTTP_BAD_REQUEST, HTTP_UNAUTHORIZED]:
            # @IMPROVE add maybe a service call / switch to deactivate sonoff component
            if self.is_grace_period():
                _LOGGER.warning("Grace period activated!")

                # return the current (and possible old) state of devices
                # in this period any change made with the mobile app (on/off) won't be shown in HA
                return self._devices

            _LOGGER.info("Re-login component")
            self.do_login()

        self._devices = r.json()['devicelist'] if 'devicelist' in r.json() else r.json()

        self.write_debug(r.text, type='D')

        return self._devices 
开发者ID:peterbuga,项目名称:HASS-sonoff-ewelink,代码行数:36,代码来源:__init__.py

示例12: request_configuration

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import string [as 别名]
def request_configuration(hass, config, host, bridge):
    """Request configuration from the user to configure a host."""
    configurator = hass.components.configurator

    if host in _CONFIGURING:
        configurator.notify_errors(
            _CONFIGURING[host],
            "Failed to process Lutron Integration Report, please try again.",
        )
        return

    def setup_callback(data):
        """Set up the callback for configuration."""
        _LOGGER.debug("Entering callback for configuring host %s", host)
        # get the integration report from callback data
        integration_report_data = data.get("integration_report")
        if not integration_report_data:
            configurator.notify_errors(
                request_id, "Error reading the Integration Report. Please try again."
            )
            return False

        # parse JSON integration report
        json_int_report = json.loads(integration_report_data)

        # check for top-level object
        if not json_int_report["LIPIdList"]:
            configurator.notify_errors(
                request_id,
                "Error parsing Integration Report. "
                "Expecting it to start "
                "with 'LIPIdList'.",
            )
            return False

        str_int_report = json.dumps(json_int_report, indent=2)
        fname = get_config_file(hass, host)
        _LOGGER.debug("Writing out JSON integration report to %s", fname)
        with open(fname, "w", encoding="utf-8") as outfile:
            outfile.write(str_int_report)

        # run setup
        _LOGGER.debug("Running setup for host %s", host)
        hass.async_add_job(async_setup_bridge, hass, config, fname, bridge)
        _LOGGER.debug("Releasing configurator.")
        configurator.request_done(request_id)

        return True

    _LOGGER.info("Requesting config from user for host %s", host)

    request_id = configurator.async_request_config(
        name="Lutron Caseta Smart Bridge PRO / Ra2 Select",
        callback=setup_callback,
        description="Enter the contents of the Integration Report:",
        fields=[
            {"id": "integration_report", "name": "Integration Report", "type": "string"}
        ],
        submit_caption="Submit",
    )
    _CONFIGURING[host] = request_id 
开发者ID:upsert,项目名称:lutron-caseta-pro,代码行数:63,代码来源:__init__.py


注:本文中的homeassistant.helpers.config_validation.string方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。