custom_components/sunpower/sensor.py
async def async_setup_entry(hass, config_entry, async_add_entities):
    """Set up the Sunpower sensors."""
    sunpower_state = hass.data[DOMAIN][config_entry.entry_id]
    _LOGGER.error("Sunpower_state: %s", sunpower_state)

    coordinator = sunpower_state[SUNPOWER_COORDINATOR]
    sunpower_data = coordinator.data

    if PVS_DEVICE_TYPE not in sunpower_data:
        _LOGGER.error("Cannot find PVS Entry")
    else:
        pvs = next(iter(sunpower_data[PVS_DEVICE_TYPE].values()))

        entities = []
        for sensor in PVS_SENSORS:
            spb = SunPowerPVSBasic(
                coordinator,
                pvs,
                PVS_SENSORS[sensor][0],
                PVS_SENSORS[sensor][1],
                PVS_SENSORS[sensor][2],
                PVS_SENSORS[sensor][3],
            )
            try:
                spb.state
                entities.append(spb)
            except KeyError:
                pass

        if METER_DEVICE_TYPE not in sunpower_data:
            _LOGGER.error("Cannot find any power meters")
        else:
            for data in sunpower_data[METER_DEVICE_TYPE].values():
                for sensor in METER_SENSORS:
                    smb = SunPowerMeterBasic(
                        coordinator,
                        data,
                        pvs,
                        METER_SENSORS[sensor][0],
                        METER_SENSORS[sensor][1],
                        METER_SENSORS[sensor][2],
                        METER_SENSORS[sensor][3],
                    )
                    try:
                        smb.state
                        entities.append(smb)
                    except KeyError:
                        pass

        if INVERTER_DEVICE_TYPE not in sunpower_data:
            _LOGGER.error("Cannot find any power inverters")
        else:
            for data in sunpower_data[INVERTER_DEVICE_TYPE].values():
                for sensor in INVERTER_SENSORS:
                    sib = SunPowerInverterBasic(
                        coordinator,
                        data,
                        pvs,
                        INVERTER_SENSORS[sensor][0],
                        INVERTER_SENSORS[sensor][1],
                        INVERTER_SENSORS[sensor][2],
                        INVERTER_SENSORS[sensor][3],
                    )
                    try:
                        sib.state
                        entities.append(sib)
                    except KeyError:
                        pass

    async_add_entities(entities, True)
Set up the Sunpower sensors.
Set up the Sunpower sensors.
Set up the Sunpower sensors .
async def async_setup_entry(hass, config_entry, async_add_entities):
    sunpower_state = hass.data[DOMAIN][config_entry.entry_id]
    _LOGGER.error("Sunpower_state: %s", sunpower_state)
    coordinator = sunpower_state[SUNPOWER_COORDINATOR]
    sunpower_data = coordinator.data
    if PVS_DEVICE_TYPE not in sunpower_data:
        _LOGGER.error("Cannot find PVS Entry")
    else:
        pvs = next(iter(sunpower_data[PVS_DEVICE_TYPE].values()))
        entities = []
        for sensor in PVS_SENSORS:
            spb = SunPowerPVSBasic(
                coordinator,
                pvs,
                PVS_SENSORS[sensor][0],
                PVS_SENSORS[sensor][1],
                PVS_SENSORS[sensor][2],
                PVS_SENSORS[sensor][3],
            )
            try:
                spb.state
                entities.append(spb)
            except KeyError:
                pass
        if METER_DEVICE_TYPE not in sunpower_data:
            _LOGGER.error("Cannot find any power meters")
        else:
            for data in sunpower_data[METER_DEVICE_TYPE].values():
                for sensor in METER_SENSORS:
                    smb = SunPowerMeterBasic(
                        coordinator,
                        data,
                        pvs,
                        METER_SENSORS[sensor][0],
                        METER_SENSORS[sensor][1],
                        METER_SENSORS[sensor][2],
                        METER_SENSORS[sensor][3],
                    )
                    try:
                        smb.state
                        entities.append(smb)
                    except KeyError:
                        pass
        if INVERTER_DEVICE_TYPE not in sunpower_data:
            _LOGGER.error("Cannot find any power inverters")
        else:
            for data in sunpower_data[INVERTER_DEVICE_TYPE].values():
                for sensor in INVERTER_SENSORS:
                    sib = SunPowerInverterBasic(
                        coordinator,
                        data,
                        pvs,
                        INVERTER_SENSORS[sensor][0],
                        INVERTER_SENSORS[sensor][1],
                        INVERTER_SENSORS[sensor][2],
                        INVERTER_SENSORS[sensor][3],
                    )
                    try:
                        sib.state
                        entities.append(sib)
                    except KeyError:
                        pass
    async_add_entities(entities, True)
async def async_setup_entry ( hass , config_entry , async_add_entities ) : sunpower_state = hass . data [ DOMAIN ] [ config_entry . entry_id ] _LOGGER . error ( "Sunpower_state: %s" , sunpower_state ) coordinator = sunpower_state [ SUNPOWER_COORDINATOR ] sunpower_data = coordinator . data if PVS_DEVICE_TYPE not in sunpower_data : _LOGGER . error ( "Cannot find PVS Entry" ) else : pvs = next ( iter ( sunpower_data [ PVS_DEVICE_TYPE ] . values ( ) ) ) entities = [ ] for sensor in PVS_SENSORS : spb = SunPowerPVSBasic ( coordinator , pvs , PVS_SENSORS [ sensor ] [ 0 ] , PVS_SENSORS [ sensor ] [ 1 ] , PVS_SENSORS [ sensor ] [ 2 ] , PVS_SENSORS [ sensor ] [ 3 ] , ) try : spb . state entities . append ( spb ) except KeyError : pass if METER_DEVICE_TYPE not in sunpower_data : _LOGGER . error ( "Cannot find any power meters" ) else : for data in sunpower_data [ METER_DEVICE_TYPE ] . values ( ) : for sensor in METER_SENSORS : smb = SunPowerMeterBasic ( coordinator , data , pvs , METER_SENSORS [ sensor ] [ 0 ] , METER_SENSORS [ sensor ] [ 1 ] , METER_SENSORS [ sensor ] [ 2 ] , METER_SENSORS [ sensor ] [ 3 ] , ) try : smb . state entities . append ( smb ) except KeyError : pass if INVERTER_DEVICE_TYPE not in sunpower_data : _LOGGER . error ( "Cannot find any power inverters" ) else : for data in sunpower_data [ INVERTER_DEVICE_TYPE ] . values ( ) : for sensor in INVERTER_SENSORS : sib = SunPowerInverterBasic ( coordinator , data , pvs , INVERTER_SENSORS [ sensor ] [ 0 ] , INVERTER_SENSORS [ sensor ] [ 1 ] , INVERTER_SENSORS [ sensor ] [ 2 ] , INVERTER_SENSORS [ sensor ] [ 3 ] , ) try : sib . state entities . append ( sib ) except KeyError : pass async_add_entities ( entities , True )
Set up the Sunpower sensors.
Set up the Sunpower sensors .
"""Set up the Sunpower sensors."""
hass
config_entry
async_add_entities