예제 #1
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Create the SolarEdge Monitoring API sensor."""
    ip_address = config[CONF_IP_ADDRESS]
    platform_name = config[CONF_NAME]

    # Create new SolarEdge object to retrieve data
    api = SolarEdge("http://{}/".format(ip_address))

    # Check if api can be reached and site is active
    try:
        status = api.get_status()

        status.energy  # pylint: disable=pointless-statement
        _LOGGER.debug("Credentials correct and site is active")
    except AttributeError:
        _LOGGER.error("Missing details data in solaredge response")
        _LOGGER.debug("Response is: %s", status)
        return
    except (ConnectTimeout, HTTPError):
        _LOGGER.error("Could not retrieve details from SolarEdge API")
        return

    # Create solaredge data service which will retrieve and update the data.
    data = SolarEdgeData(hass, api)

    # Create a new sensor for each sensor type.
    entities = []
    for sensor_key in SENSOR_TYPES:
        sensor = SolarEdgeSensor(platform_name, sensor_key, data)
        entities.append(sensor)

    add_entities(entities, True)
예제 #2
0
파일: sensor.py 프로젝트: 2Fake/core
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Create the SolarEdge Monitoring API sensor."""
    ip_address = config[CONF_IP_ADDRESS]
    platform_name = config[CONF_NAME]

    # Create new SolarEdge object to retrieve data.
    api = SolarEdge(f"http://{ip_address}/")

    # Check if api can be reached and site is active.
    try:
        status = api.get_status()
        _LOGGER.debug("Credentials correct and site is active")
    except AttributeError:
        _LOGGER.error("Missing details data in solaredge status")
        _LOGGER.debug("Status is: %s", status)
        return
    except (ConnectTimeout, HTTPError):
        _LOGGER.error("Could not retrieve details from SolarEdge API")
        return

    # Create solaredge data service which will retrieve and update the data.
    data = SolarEdgeData(hass, api)

    # Changing inverter temperature unit.
    inverter_temp_description = copy(SENSOR_TYPE_INVERTER_TEMPERATURE)
    if status.inverters.primary.temperature.units.farenheit:
        inverter_temp_description.native_unit_of_measurement = TEMP_FAHRENHEIT

    # Create entities
    entities = [
        SolarEdgeSensor(platform_name, data, description)
        for description in (*SENSOR_TYPES, inverter_temp_description)
    ]

    try:
        if status.metersList[0]:
            entities.extend([
                SolarEdgeSensor(platform_name, data, description)
                for description in SENSOR_TYPES_ENERGY_IMPORT
            ])
    except IndexError:
        _LOGGER.debug("Import meter sensors are not created")

    try:
        if status.metersList[1]:
            entities.extend([
                SolarEdgeSensor(platform_name, data, description)
                for description in SENSOR_TYPES_ENERGY_EXPORT
            ])
    except IndexError:
        _LOGGER.debug("Export meter sensors are not created")

    add_entities(entities, True)
예제 #3
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Create the SolarEdge Monitoring API sensor."""
    ip_address = config[CONF_IP_ADDRESS]
    platform_name = config[CONF_NAME]

    # Create new SolarEdge object to retrieve data.
    api = SolarEdge(f"http://{ip_address}/")

    # Check if api can be reached and site is active.
    try:
        status = api.get_status()
        _LOGGER.debug("Credentials correct and site is active")
    except AttributeError:
        _LOGGER.error("Missing details data in solaredge status")
        _LOGGER.debug("Status is: %s", status)
        return
    except (ConnectTimeout, HTTPError):
        _LOGGER.error("Could not retrieve details from SolarEdge API")
        return

    # Changing inverter temperature unit.
    sensors = deepcopy(SENSOR_TYPES)
    if status.inverters.primary.temperature.units.farenheit:
        sensors["inverter_temperature"] = [
            "invertertemperature",
            "Inverter Temperature",
            TEMP_FAHRENHEIT,
            "mdi:thermometer",
        ]

    # Create solaredge data service which will retrieve and update the data.
    data = SolarEdgeData(hass, api)

    # Create a new sensor for each sensor type.
    entities = []
    for sensor_info in sensors.values():
        sensor = SolarEdgeSensor(
            platform_name,
            data,
            sensor_info[0],
            sensor_info[1],
            sensor_info[2],
            sensor_info[3],
        )
        entities.append(sensor)

    add_entities(entities, True)
예제 #4
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Create the SolarEdge Monitoring API sensor."""
    ip_address = config[CONF_IP_ADDRESS]
    platform_name = config[CONF_NAME]

    # Create new SolarEdge object to retrieve data.
    api = SolarEdge(f"http://{ip_address}/")

    # Check if api can be reached and site is active.
    try:
        status = api.get_status()
        _LOGGER.debug("Credentials correct and site is active")
    except AttributeError:
        _LOGGER.error("Missing details data in solaredge status")
        _LOGGER.debug("Status is: %s", status)
        return
    except (ConnectTimeout, HTTPError):
        _LOGGER.error("Could not retrieve details from SolarEdge API")
        return

    # Changing inverter temperature unit.
    sensors = deepcopy(SENSOR_TYPES)
    if status.inverters.primary.temperature.units.farenheit:
        sensors["inverter_temperature"] = [
            "invertertemperature",
            "Inverter Temperature",
            TEMP_FAHRENHEIT,
            "mdi:thermometer",
            "operating_mode",
            DEVICE_CLASS_TEMPERATURE,
        ]

    try:
        if status.metersList[0]:
            sensors["import_current_power"] = [
                "currentPowerimport",
                "current import Power",
                POWER_WATT,
                "mdi:arrow-collapse-down",
                None,
                None,
            ]
            sensors["import_meter_reading"] = [
                "totalEnergyimport",
                "total import Energy",
                ENERGY_WATT_HOUR,
                "mdi:counter",
                None,
                None,
            ]
    except IndexError:
        _LOGGER.debug("Import meter sensors are not created")

    try:
        if status.metersList[1]:
            sensors["export_current_power"] = [
                "currentPowerexport",
                "current export Power",
                POWER_WATT,
                "mdi:arrow-expand-up",
                None,
                None,
            ]
            sensors["export_meter_reading"] = [
                "totalEnergyexport",
                "total export Energy",
                ENERGY_WATT_HOUR,
                "mdi:counter",
                None,
                None,
            ]
    except IndexError:
        _LOGGER.debug("Export meter sensors are not created")

    # Create solaredge data service which will retrieve and update the data.
    data = SolarEdgeData(hass, api)

    # Create a new sensor for each sensor type.
    entities = []
    for sensor_info in sensors.values():
        sensor = SolarEdgeSensor(
            platform_name,
            data,
            sensor_info[0],
            sensor_info[1],
            sensor_info[2],
            sensor_info[3],
            sensor_info[4],
            sensor_info[5],
        )
        entities.append(sensor)

    add_entities(entities, True)