29
29
CONF_SECRET ,
30
30
CONF_KEY_ID ,
31
31
CONF_PLANT_ID ,
32
- CONF_INVERTER_SERIAL ,
33
- CONF_SENSORS ,
34
32
SENSOR_PREFIX ,
35
33
DEFAULT_DOMAIN ,
36
34
SENSOR_TYPES ,
44
42
_LOGGER = logging .getLogger (__name__ )
45
43
46
44
# VERSION
47
- VERSION = '2.1 .0'
45
+ VERSION = '2.2 .0'
48
46
49
47
LAST_UPDATED = 'Last updated'
50
48
SERIAL = 'Inverter serial'
54
52
SERIAL : None ,
55
53
}
56
54
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
75
73
76
74
PLATFORM_SCHEMA = vol .All (PLATFORM_SCHEMA .extend ({
77
75
vol .Optional (CONF_NAME , default = SENSOR_PREFIX ): cv .string ,
@@ -81,8 +79,6 @@ def _check_config_schema(conf: ConfigType):
81
79
vol .Optional (CONF_SECRET , default = '00' ): cv .string ,
82
80
vol .Optional (CONF_KEY_ID , default = '' ): cv .string ,
83
81
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 }),
86
82
}, extra = vol .PREVENT_EXTRA ), _check_config_schema )
87
83
88
84
def create_sensors (sensors : dict [str , list [str ]],
@@ -98,20 +94,6 @@ def create_sensors(sensors: dict[str, list[str]],
98
94
inverter_sn , sensor_type ))
99
95
return hass_sensors
100
96
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
-
115
97
async def async_setup_platform (
116
98
hass : HomeAssistant ,
117
99
config : ConfigType ,
@@ -126,15 +108,7 @@ async def async_setup_platform(
126
108
portal_key_id = config .get (CONF_KEY_ID )
127
109
portal_secret : bytes = bytes (config .get (CONF_SECRET ), 'utf-8' )
128
110
portal_plantid = config .get (CONF_PLANT_ID )
129
- inverter_sn = config .get (CONF_INVERTER_SERIAL )
130
111
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' )
138
112
portal_config : PortalConfig | None = None
139
113
if portal_password != '' :
140
114
portal_config = GinlongConfig (
@@ -144,31 +118,21 @@ async def async_setup_platform(
144
118
portal_domain , portal_username , portal_key_id , portal_secret , portal_plantid )
145
119
else :
146
120
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' )
149
121
150
122
# Initialize the Ginlong data service.
151
123
service : InverterService = InverterService (portal_config , hass )
152
124
153
125
# Prepare the sensor entities.
154
126
hass_sensors : list [SolisSensor ] = []
155
127
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 )
172
136
173
137
@callback
174
138
def on_discovered (capabilities , cookie ):
0 commit comments