Skip to content

Commit 47f19cc

Browse files
authored
Merge pull request #107 from hultenvp/30_Remove_deprecated_config
30 remove deprecated config
2 parents 40a79dc + cd4fa9a commit 47f19cc

File tree

3 files changed

+28
-66
lines changed

3 files changed

+28
-66
lines changed

custom_components/solis/const.py

-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
CONF_SECRET = 'portal_secret'
3030
CONF_KEY_ID = 'portal_key_id'
3131
CONF_PLANT_ID = 'portal_plant_id'
32-
CONF_INVERTER_SERIAL = 'inverter_serial'
33-
CONF_SENSORS = 'sensors'
3432

3533
SENSOR_PREFIX = 'Solis'
3634
DEFAULT_DOMAIN = 'm.ginlong.com'

custom_components/solis/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"domain": "solis",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"name": "Solis Inverter",
55
"iot_class": "cloud_push",
66
"documentation": "https://github.com/hultenvp/solis-sensor/",

custom_components/solis/sensor.py

+27-63
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
CONF_SECRET,
3030
CONF_KEY_ID,
3131
CONF_PLANT_ID,
32-
CONF_INVERTER_SERIAL,
33-
CONF_SENSORS,
3432
SENSOR_PREFIX,
3533
DEFAULT_DOMAIN,
3634
SENSOR_TYPES,
@@ -44,7 +42,7 @@
4442
_LOGGER = logging.getLogger(__name__)
4543

4644
# VERSION
47-
VERSION = '2.1.0'
45+
VERSION = '2.2.0'
4846

4947
LAST_UPDATED = 'Last updated'
5048
SERIAL = 'Inverter serial'
@@ -54,24 +52,24 @@
5452
SERIAL: None,
5553
}
5654

57-
def _check_config_schema(conf: ConfigType):
58-
"""Check if the sensors and attributes are valid."""
59-
if CONF_SENSORS in conf.keys():
60-
_LOGGER.warning("Deprecated platform configuration, please move to the new configuration")
61-
if conf[CONF_INVERTER_SERIAL] == '':
62-
raise vol.Invalid('inverter_serial required in config when sensors are specified')
63-
64-
for sensor, attrs in conf[CONF_SENSORS].items():
65-
if sensor not in SENSOR_TYPES:
66-
raise vol.Invalid('sensor {} does not exist'.format(sensor))
67-
for attr in attrs:
68-
if attr not in SENSOR_TYPES:
69-
raise vol.Invalid('attribute sensor {} does not \
70-
exist [{}]'.format(attr, sensor))
71-
else:
72-
if conf[CONF_INVERTER_SERIAL] != '':
73-
_LOGGER.warning("Using new config schema, ignoring inverter_serial")
74-
return conf
55+
def _check_config_schema(config: ConfigType):
56+
# Check input configuration.
57+
portal_domain = config.get(CONF_PORTAL_DOMAIN)
58+
if portal_domain is None:
59+
raise vol.Invalid('configuration parameter [portal_domain] does not have a value')
60+
elif portal_domain[:4] == 'http':
61+
raise vol.Invalid('leave http(s):// out of configuration parameter [portal_domain]')
62+
if config.get(CONF_USERNAME) is None:
63+
raise vol.Invalid('configuration parameter [portal_username] does not have a value')
64+
if config.get(CONF_PLANT_ID) is None:
65+
raise vol.Invalid('Configuration parameter [portal_plantid] does not have a value')
66+
has_password = config.get(CONF_PASSWORD) != ''
67+
has_key_id = config.get(CONF_KEY_ID) != ''
68+
has_secret: bytes = bytes(config.get(CONF_SECRET), 'utf-8') != b'\x00'
69+
if not (has_password ^ (has_key_id and has_secret)):
70+
raise vol.Invalid('Please specify either[portal_password] or [portal_key_id] & [portal_secret]')
71+
72+
return config
7573

7674
PLATFORM_SCHEMA = vol.All(PLATFORM_SCHEMA.extend({
7775
vol.Optional(CONF_NAME, default=SENSOR_PREFIX): cv.string,
@@ -81,8 +79,6 @@ def _check_config_schema(conf: ConfigType):
8179
vol.Optional(CONF_SECRET , default='00'): cv.string,
8280
vol.Optional(CONF_KEY_ID , default=''): cv.string,
8381
vol.Required(CONF_PLANT_ID, default=None): cv.positive_int,
84-
vol.Optional(CONF_INVERTER_SERIAL, default=''): cv.string,
85-
vol.Optional(CONF_SENSORS): vol.Schema({cv.slug: cv.ensure_list}),
8682
}, extra=vol.PREVENT_EXTRA), _check_config_schema)
8783

8884
def create_sensors(sensors: dict[str, list[str]],
@@ -98,20 +94,6 @@ def create_sensors(sensors: dict[str, list[str]],
9894
inverter_sn, sensor_type))
9995
return hass_sensors
10096

101-
def create_sensors_legacy(
102-
config: ConfigType,
103-
inverter_service: InverterService,
104-
inverter_name: str,
105-
inverter_sn: str
106-
) -> list[SolisSensor]:
107-
"""Legacy for old config schema."""
108-
hass_sensors = []
109-
for sensor_type, subtypes in config[CONF_SENSORS].items():
110-
_LOGGER.debug("Creating %s sensor: %s", inverter_name, sensor_type)
111-
hass_sensors.append(SolisSensor(inverter_service, inverter_name,
112-
inverter_sn, sensor_type))
113-
return hass_sensors
114-
11597
async def async_setup_platform(
11698
hass: HomeAssistant,
11799
config: ConfigType,
@@ -126,15 +108,7 @@ async def async_setup_platform(
126108
portal_key_id = config.get(CONF_KEY_ID)
127109
portal_secret: bytes = bytes(config.get(CONF_SECRET), 'utf-8')
128110
portal_plantid = config.get(CONF_PLANT_ID)
129-
inverter_sn = config.get(CONF_INVERTER_SERIAL)
130111

131-
# Check input configuration.
132-
if portal_domain is None:
133-
raise vol.Invalid('configuration parameter [portal_domain] does not have a value')
134-
if portal_domain[:4] == 'http':
135-
raise vol.Invalid('leave http(s):// out of configuration parameter [portal_domain]')
136-
if portal_username is None:
137-
raise vol.Invalid('configuration parameter [portal_username] does not have a value')
138112
portal_config: PortalConfig | None = None
139113
if portal_password != '':
140114
portal_config = GinlongConfig(
@@ -144,31 +118,21 @@ async def async_setup_platform(
144118
portal_domain, portal_username, portal_key_id, portal_secret, portal_plantid)
145119
else:
146120
raise vol.Invalid('Please specify either[portal_password] or [portal_key_id] & [portal_secret]')
147-
if portal_plantid is None:
148-
raise vol.Invalid('Configuration parameter [portal_plantid] does not have a value')
149121

150122
# Initialize the Ginlong data service.
151123
service: InverterService = InverterService(portal_config, hass)
152124

153125
# Prepare the sensor entities.
154126
hass_sensors: list[SolisSensor] = []
155127

156-
if CONF_SENSORS in config.keys():
157-
# Old config schema
158-
hass_sensors = create_sensors_legacy(config, service, inverter_name, inverter_sn)
159-
async_add_entities(hass_sensors)
160-
161-
# schedule the first update in 1 minute from now:
162-
service.schedule_update(1)
163-
else:
164-
cookie: dict[str, Any] = {
165-
'name': inverter_name,
166-
'service': service,
167-
'async_add_entities' : async_add_entities
168-
}
169-
# Will retry endlessly to discover
170-
_LOGGER.info("Scheduling discovery")
171-
service.schedule_discovery(on_discovered, cookie, 1)
128+
cookie: dict[str, Any] = {
129+
'name': inverter_name,
130+
'service': service,
131+
'async_add_entities' : async_add_entities
132+
}
133+
# Will retry endlessly to discover
134+
_LOGGER.info("Scheduling discovery")
135+
service.schedule_discovery(on_discovered, cookie, 1)
172136

173137
@callback
174138
def on_discovered(capabilities, cookie):

0 commit comments

Comments
 (0)