Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/solax/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Solax Inverter",
"documentation": "https://www.home-assistant.io/components/solax",
"requirements": [
"solax==0.1.2"
"solax==0.2.2"
],
"dependencies": [],
"codeowners": ["@squishykid"]
Expand Down
26 changes: 14 additions & 12 deletions homeassistant/components/solax/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
from datetime import timedelta
import logging

from solax import real_time_api
from solax.inverter import InverterError
import voluptuous as vol

from homeassistant.const import TEMP_CELSIUS, CONF_IP_ADDRESS
from homeassistant.const import TEMP_CELSIUS, CONF_IP_ADDRESS, CONF_PORT
from homeassistant.helpers.entity import Entity
import homeassistant.helpers.config_validation as cv
from homeassistant.components.sensor import PLATFORM_SCHEMA
Expand All @@ -15,24 +17,26 @@

_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({vol.Required(CONF_IP_ADDRESS): cv.string})
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_IP_ADDRESS): cv.string,
vol.Optional(CONF_PORT, default=80): cv.port,
Comment thread
squishykid marked this conversation as resolved.
Outdated
}
)

SCAN_INTERVAL = timedelta(seconds=30)


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Platform setup."""
import solax

api = solax.RealTimeAPI(config[CONF_IP_ADDRESS])
api = await real_time_api(config[CONF_IP_ADDRESS], config[CONF_PORT])
endpoint = RealTimeDataEndpoint(hass, api)
resp = await api.get_data()
serial = resp.serial_number
hass.async_add_job(endpoint.async_refresh)
async_track_time_interval(hass, endpoint.async_refresh, SCAN_INTERVAL)
devices = []
for sensor in solax.INVERTER_SENSORS:
idx, unit = solax.INVERTER_SENSORS[sensor]
for sensor, (idx, unit) in api.inverter.sensor_map().items():
if unit == "C":
unit = TEMP_CELSIUS
uid = f"{serial}-{idx}"
Expand All @@ -56,16 +60,14 @@ async def async_refresh(self, now=None):

This is the only method that should fetch new data for Home Assistant.
"""
from solax import SolaxRequestError

try:
api_response = await self.api.get_data()
self.ready.set()
except SolaxRequestError:
except InverterError:
if now is not None:
self.ready.clear()
else:
raise PlatformNotReady
return
raise PlatformNotReady
data = api_response.data
for sensor in self.sensors:
if sensor.key in data:
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,7 @@ solaredge-local==0.1.4
solaredge==0.0.2

# homeassistant.components.solax
solax==0.1.2
solax==0.2.2

# homeassistant.components.honeywell
somecomfort==0.5.2
Expand Down