def hex_int_(value): if isinstance(value, integer_types): return HexInt(value) value = string_strict(value).lower() if value.startswith('0x'): return HexInt(int(value, 16)) return HexInt(int(value))
def to_code(config): from PIL import Image path = CORE.relative_path(config[CONF_FILE]) try: image = Image.open(path) except Exception as e: raise core.pi4homeError(u"Could not load image file {}: {}".format(path, e)) if CONF_RESIZE in config: image.thumbnail(config[CONF_RESIZE]) image = image.convert('1', dither=Image.NONE) width, height = image.size if width > 500 or height > 500: _LOGGER.warning("The image you requested is very big. Please consider using the resize " "parameter") width8 = ((width + 7) // 8) * 8 data = [0 for _ in range(height * width8 // 8)] for y in range(height): for x in range(width): if image.getpixel((x, y)): continue pos = x + y * width8 data[pos // 8] |= 0x80 >> (pos % 8) rhs = safe_exp([HexInt(x) for x in data]) prog_arr = progmem_array(config[CONF_RAW_DATA_ID], rhs) rhs = App.make_image(prog_arr, width, height) Pvariable(config[CONF_ID], rhs)
def to_code(config): for uart_ in get_variable(config[CONF_UART_ID]): yield data = config[CONF_DATA] if isinstance(data, str): data = [HexInt(ord(x)) for x in data] rhs = App.make_uart_switch(uart_, config[CONF_NAME], data) var = Pvariable(config[CONF_ID], rhs) switch.setup_switch(var, config)
def wifi_network(config, static_ip): ap = variable(config[CONF_ID], WiFiAP()) if CONF_SSID in config: add(ap.set_ssid(config[CONF_SSID])) if CONF_PASSWORD in config: add(ap.set_password(config[CONF_PASSWORD])) if CONF_BSSID in config: add(ap.set_bssid([HexInt(i) for i in config[CONF_BSSID].parts])) if CONF_HIDDEN in config: add(ap.set_hidden(config[CONF_HIDDEN])) if CONF_CHANNEL in config: add(ap.set_channel(config[CONF_CHANNEL])) if static_ip is not None: add(ap.set_manual_ip(manual_ip(static_ip))) return ap
def __init__(self, i): # type: (int) -> None super(HexIntLiteral, self).__init__() self.i = HexInt(i)
def make_address_array(address): return [HexInt(i) for i in address.parts]
def binary_code(value): code = 0 for val in value: code <<= 1 code |= val == '1' return HexInt(code)
def to_code(config): for hub in get_variable(config[CONF_PN532_ID]): yield addr = [HexInt(int(x, 16)) for x in config[CONF_UID].split('-')] rhs = hub.make_tag(config[CONF_NAME], addr) binary_sensor.register_binary_sensor(rhs, config)