Add support for aurora ABB Powerone solar photovoltaic inverter (#24809)

* Add support for aurora ABB Powerone solar photovoltaic inverter

* Add support for aurora ABB Powerone solar photovoltaic inverter

* Update stale docstring

* Fixed whitespace lint errors

* Remove test code

* Delete README.md

Website documentation contains setup instructions.  README not needed here.

* Only close the serial line once.

* Correct newlines between imports

* Change add_devices to add_entites and remove unnecessary logging.

* Use new style string formatting instead of concatenation

* Directly access variables rather than via config.get

* Update sensor.py
This commit is contained in:
Dave T 2019-07-07 10:22:21 +01:00 committed by Pascal Vizeli
parent 628e12c944
commit 6e24b52a7e
6 changed files with 114 additions and 0 deletions

View file

@ -49,6 +49,7 @@ omit =
homeassistant/components/asterisk_mbox/*
homeassistant/components/asuswrt/device_tracker.py
homeassistant/components/august/*
homeassistant/components/aurora_abb_powerone/sensor.py
homeassistant/components/automatic/device_tracker.py
homeassistant/components/avion/light.py
homeassistant/components/azure_event_hub/*

View file

@ -29,6 +29,7 @@ homeassistant/components/aprs/* @PhilRW
homeassistant/components/arduino/* @fabaff
homeassistant/components/arest/* @fabaff
homeassistant/components/asuswrt/* @kennedyshead
homeassistant/components/aurora_abb_powerone/* @davet2001
homeassistant/components/auth/* @home-assistant/core
homeassistant/components/automatic/* @armills
homeassistant/components/automation/* @home-assistant/core

View file

@ -0,0 +1 @@
"""The Aurora ABB Powerone PV inverter sensor integration."""

View file

@ -0,0 +1,10 @@
{
"domain": "aurora_abb_powerone",
"name": "Aurora ABB Solar PV",
"documentation": "https://www.home-assistant.io/components/aurora_abb_powerone/",
"dependencies": [],
"codeowners": [
"@davet2001"
],
"requirements": ["aurorapy==0.2.6"]
}

View file

@ -0,0 +1,98 @@
"""Support for Aurora ABB PowerOne Solar Photvoltaic (PV) inverter."""
import logging
import voluptuous as vol
from aurorapy.client import AuroraSerialClient, AuroraError
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import (
CONF_ADDRESS, CONF_DEVICE, CONF_NAME, DEVICE_CLASS_POWER,
POWER_WATT)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__)
DEFAULT_ADDRESS = 2
DEFAULT_NAME = "Solar PV"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_DEVICE): cv.string,
vol.Optional(CONF_ADDRESS, default=DEFAULT_ADDRESS): cv.positive_int,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})
def setup_platform(hass, 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)
class AuroraABBSolarPVMonitorSensor(Entity):
"""Representation of a Sensor."""
def __init__(self, client, name, typename):
"""Initialize the sensor."""
self._name = "{} {}".format(name, typename)
self.client = client
self._state = None
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
"""Return the unit of measurement."""
return POWER_WATT
@property
def device_class(self):
"""Return the device class."""
return DEVICE_CLASS_POWER
def update(self):
"""Fetch new state data for the sensor.
This is the only method that should fetch new data for Home Assistant.
"""
try:
self.client.connect()
# read ADC channel 3 (grid power output)
power_watts = self.client.measure(3, True)
self._state = round(power_watts, 1)
# _LOGGER.debug("Got reading %fW" % self._state)
except AuroraError as error:
# aurorapy does not have different exceptions (yet) for dealing
# with timeout vs other comms errors.
# This means the (normal) situation of no response during darkness
# raises an exception.
# aurorapy (gitlab) pull request merged 29/5/2019. When >0.2.6 is
# released, this could be modified to :
# except AuroraTimeoutError as e:
# Workaround: look at the text of the exception
if "No response after" in str(error):
_LOGGER.debug("No response from inverter (could be dark)")
else:
# print("Exception!!: {}".format(str(e)))
raise error
self._state = None
finally:
if self.client.serline.isOpen():
self.client.close()

View file

@ -211,6 +211,9 @@ asterisk_mbox==0.5.0
# homeassistant.components.upnp
async-upnp-client==0.14.10
# homeassistant.components.aurora_abb_powerone
aurorapy==0.2.6
# homeassistant.components.stream
av==6.1.2