def __init__(self, config):
     """Initialize the sensor."""
     self.clientABB = AuroraSerialClient(config['aurora']['address'],
                                         config['aurora']['com_port'],
                                         parity="N",
                                         timeout=1)
     self.clientABB.connect()
     self.state()
     self.temperature()
     self.cumulated()
     self.monitoring()
Beispiel #2
0
def validate_and_connect(hass: core.HomeAssistant, data):
    """Validate the user input allows us to connect.

    Data has the keys from DATA_SCHEMA with values provided by the user.
    """
    comport = data[CONF_PORT]
    address = data[CONF_ADDRESS]
    _LOGGER.debug("Intitialising com port=%s", comport)
    ret = {}
    ret["title"] = DEFAULT_INTEGRATION_TITLE
    try:
        client = AuroraSerialClient(address, comport, parity="N", timeout=1)
        client.connect()
        ret[ATTR_SERIAL_NUMBER] = client.serial_number()
        ret[ATTR_MODEL] = f"{client.version()} ({client.pn()})"
        ret[ATTR_FIRMWARE] = client.firmware(1)
        _LOGGER.info("Returning device info=%s", ret)
    except AuroraError as err:
        _LOGGER.warning("Could not connect to device=%s", comport)
        raise err
    finally:
        if client.serline.isOpen():
            client.close()

    # Return info we want to store in the config entry.
    return ret
Beispiel #3
0
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Set up Aurora ABB PowerOne from a config entry."""

    comport = entry.data[CONF_PORT]
    address = entry.data[CONF_ADDRESS]
    ser_client = AuroraSerialClient(address, comport, parity="N", timeout=1)
    hass.data.setdefault(DOMAIN, {})[entry.entry_id] = ser_client
    await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

    return True
Beispiel #4
0
def setup_platform(opp, config, add_entities, discovery_info=None):
    """Set up the Aurora ABB PowerOne device."""
    devices = []
    comport = config[CONF_DEVICE]
    address = config[CONF_ADDRESS]
    name = config[CONF_NAME]

    _LOGGER.debug("Intitialising com port=%s address=%s", comport, address)
    client = AuroraSerialClient(address, comport, parity="N", timeout=1)

    devices.append(AuroraABBSolarPVMonitorSensor(client, name, "Power"))
    add_entities(devices, True)
Beispiel #5
0
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Set up Aurora ABB PowerOne from a config entry."""

    comport = entry.data[CONF_PORT]
    address = entry.data[CONF_ADDRESS]
    ser_client = AuroraSerialClient(address, comport, parity="N", timeout=1)
    # To handle yaml import attempts in darkeness, (re)try connecting only if
    # unique_id not yet assigned.
    if entry.unique_id is None:
        try:
            res = await hass.async_add_executor_job(validate_and_connect, hass,
                                                    entry.data)
        except AuroraError as error:
            if "No response after" in str(error):
                raise ConfigEntryNotReady(
                    "No response (could be dark)") from error
            _LOGGER.error("Failed to connect to inverter: %s", error)
            return False
        except OSError as error:
            if error.errno == 19:  # No such device.
                _LOGGER.error(
                    "Failed to connect to inverter: no such COM port")
                return False
            _LOGGER.error("Failed to connect to inverter: %s", error)
            return False
        else:
            # If we got here, the device is now communicating (maybe after
            # being in darkness). But there's a small risk that the user has
            # configured via the UI since we last attempted the yaml setup,
            # which means we'd get a duplicate unique ID.
            new_id = res[ATTR_SERIAL_NUMBER]
            # Check if this unique_id has already been used
            for existing_entry in hass.config_entries.async_entries(DOMAIN):
                if existing_entry.unique_id == new_id:
                    _LOGGER.debug(
                        "Remove already configured config entry for id %s",
                        new_id)
                    hass.async_create_task(
                        hass.config_entries.async_remove(entry.entry_id))
                    return False
            hass.config_entries.async_update_entry(entry, unique_id=new_id)

    hass.data.setdefault(DOMAIN, {})[entry.entry_id] = ser_client
    hass.config_entries.async_setup_platforms(entry, PLATFORMS)

    return True
class ABBAuroraMonitoring():
    def __init__(self, config):
        """Initialize the sensor."""
        self.clientABB = AuroraSerialClient(config['aurora']['address'],
                                            config['aurora']['com_port'],
                                            parity="N",
                                            timeout=1)
        self.clientABB.connect()
        self.state()
        self.temperature()
        self.cumulated()
        self.monitoring()

    def close(self):
        self.clientABB.close()

    def state(self):
        obj = {}
        obj['global_state'] = (self.clientABB.state(1))
        obj['alarm'] = (self.clientABB.state(5))
        self.status = obj

    def temperature(self):
        obj = {}
        obj['inverter'] = round(self.clientABB.measure(21), 1)
        obj['booster'] = round(self.clientABB.measure(22), 1)
        self.temp = obj

    def cumulated(self):
        obj = {}
        obj['curent_day'] = round(self.clientABB.cumulated_energy(0), 1)
        obj['week'] = round(self.clientABB.cumulated_energy(1), 1)
        obj['month'] = round(self.clientABB.cumulated_energy(4), 1)
        obj['total'] = round(self.clientABB.cumulated_energy(6), 1)
        self.cumulated_energy = obj

    def monitoring(self):
        obj = {}
        obj['grid_voltage'] = round(self.clientABB.measure(1), 1)
        obj['grid_power'] = round(self.clientABB.measure(3, True), 1)
        obj['vbulk'] = round(self.clientABB.measure(5), 1)
        obj['leak_dc'] = round(self.clientABB.measure(6), 1)
        obj['leak_Inverter'] = round(self.clientABB.measure(7), 1)
        obj['power_peak'] = round(self.clientABB.measure(35), 1)
        self.monitoring_status = obj