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
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