def to_code(config): rhs = App.make_ina3221(config[CONF_ADDRESS], config.get(CONF_UPDATE_INTERVAL)) ina = Pvariable(config[CONF_ID], rhs) for i, channel in enumerate( [CONF_CHANNEL_1, CONF_CHANNEL_2, CONF_CHANNEL_3]): if channel not in config: continue conf = config[channel] if CONF_SHUNT_RESISTANCE in conf: add(ina.set_shunt_resistance(i, conf[CONF_SHUNT_RESISTANCE])) if CONF_BUS_VOLTAGE in conf: c = conf[CONF_BUS_VOLTAGE] sensor.register_sensor( ina.Pmake_bus_voltage_sensor(i, c[CONF_NAME]), c) if CONF_SHUNT_VOLTAGE in conf: c = conf[CONF_SHUNT_VOLTAGE] sensor.register_sensor( ina.Pmake_shunt_voltage_sensor(i, c[CONF_NAME]), c) if CONF_CURRENT in conf: c = conf[CONF_CURRENT] sensor.register_sensor(ina.Pmake_current_sensor(i, c[CONF_NAME]), c) if CONF_POWER in conf: c = conf[CONF_POWER] sensor.register_sensor(ina.Pmake_power_sensor(i, c[CONF_NAME]), c) setup_component(ina, config)
def to_code(config): rhs = App.make_ina219(config[CONF_SHUNT_RESISTANCE], config[CONF_MAX_CURRENT], config[CONF_MAX_VOLTAGE], config[CONF_ADDRESS], config.get(CONF_UPDATE_INTERVAL)) ina = Pvariable(config[CONF_ID], rhs) if CONF_BUS_VOLTAGE in config: conf = config[CONF_BUS_VOLTAGE] sensor.register_sensor(ina.Pmake_bus_voltage_sensor(conf[CONF_NAME]), conf) if CONF_SHUNT_VOLTAGE in config: conf = config[CONF_SHUNT_VOLTAGE] sensor.register_sensor(ina.Pmake_shunt_voltage_sensor(conf[CONF_NAME]), conf) if CONF_CURRENT in config: conf = config[CONF_CURRENT] sensor.register_sensor(ina.Pmake_current_sensor(conf[CONF_NAME]), conf) if CONF_POWER in config: conf = config[CONF_POWER] sensor.register_sensor(ina.Pmake_power_sensor(conf[CONF_NAME]), conf) setup_component(ina, config)