@@ -35,7 +35,9 @@ public StatusChangedEventArgs(GoodWeStatus status)
3535 }
3636
3737 internal EventHandler < StatusChangedEventArgs > StatusChanged = delegate { } ;
38-
38+
39+ private GoodWeClient ? _client ;
40+
3941 private CaseInsensitiveDictionary < string ? > ? _optionsBackup ;
4042
4143 private void SetStatus ( GoodWeStatus status )
@@ -85,9 +87,9 @@ private async Task ReadDeviceInfoAsync()
8587
8688 var client = new GoodWeClient ( _logger , null , accountConfig ) ;
8789
88- var stats = await client . GetPlantListAsync ( new CancellationToken ( ) ) ;
90+ var plantList = await client . GetPlantListAsync ( new CancellationToken ( ) ) ;
8991
90- if ( stats . Data == null )
92+ if ( plantList . Data == null )
9193 {
9294 SetStatus ( GoodWeStatus . Uninitialized ) ;
9395 statusLabel . Text = "Could not obtain inverter list, verify your email and password on semsportal.com." ;
@@ -97,7 +99,7 @@ private async Task ReadDeviceInfoAsync()
9799
98100 SetStatus ( GoodWeStatus . Authorized ) ;
99101
100- var firstPlant = stats . Data . list ? . FirstOrDefault ( ) ;
102+ var firstPlant = plantList . Data . list ? . FirstOrDefault ( ) ;
101103
102104 if ( firstPlant ? . inverters ? . Any ( ) != true )
103105 {
@@ -106,25 +108,32 @@ private async Task ReadDeviceInfoAsync()
106108 return ;
107109 }
108110
109- var plantCount = stats . Data . list ? . Count ?? 0 ;
110- var inverterCount = stats . Data . list ? . Sum ( p => p . inverters ? . Count ) ;
111-
112- statusLabel . Text = $ "Found { plantCount } plant{ ( plantCount == 1 ? "" : "s" ) } with { inverterCount } inverter{ ( inverterCount == 1 ? "" : "s" ) } ";
113-
114111 plantComboBox . Enabled = true ;
115112 plantComboBox . ValueMember = nameof ( AddressWithInverters . id ) ;
116113 plantComboBox . DisplayMember = nameof ( AddressWithInverters . DisplayString ) ;
117- plantComboBox . DataSource = stats . Data . list ;
114+
115+ _client = client ;
116+ plantComboBox . DataSource = plantList . Data . list ;
118117
119118 plantComboBox . SelectedIndex = 0 ;
119+
120+ var plantCount = plantList . Data . list ? . Count ?? 0 ;
121+ var inverterCount = plantList . Data . list ? . Sum ( p => p . inverters ? . Count ) ?? 0 ;
122+
123+ if ( inverterCount > 0 )
124+ {
125+ statusLabel . Text = $ "Found { plantCount . SIfPlural ( "plant" ) } with { inverterCount . SIfPlural ( "inverter" ) } ";
126+ }
120127 }
121128
122- private void PlantComboBox_SelectedValueChanged ( object sender , EventArgs e )
129+ private async void PlantComboBox_SelectedValueChanged ( object sender , EventArgs e )
123130 {
124131 ResetComboBox ( inverterComboBox ) ;
125132
126133 if ( plantComboBox . SelectedItem == null )
127134 {
135+ _client = null ;
136+
128137 SetStatus ( GoodWeStatus . Uninitialized ) ;
129138
130139 return ;
@@ -139,7 +148,26 @@ private void PlantComboBox_SelectedValueChanged(object sender, EventArgs e)
139148 return ;
140149 }
141150
142- statusLabel . Text = "" ;
151+ if ( plant . inverters . Any ( p => p . turnon_time == null ) )
152+ {
153+ var deets = await _client ! . GetMonitorDetailRaw ( plant . id ! , new CancellationToken ( ) ) ;
154+ if ( deets . Data ? . inverter ? . Any ( ) != true )
155+ {
156+ statusLabel . Text = "No inverters details found for selected plant." ;
157+
158+ return ;
159+ }
160+
161+ foreach ( var inverter in plant . inverters )
162+ {
163+ var inverterDetails = deets . Data . inverter . FirstOrDefault ( i => i . sn == inverter . sn ) ;
164+
165+ if ( inverterDetails ? . turnon_time != null )
166+ {
167+ inverter . turnon_time = inverterDetails . turnon_time ;
168+ }
169+ }
170+ }
143171
144172 inverterComboBox . Enabled = true ;
145173 inverterComboBox . ValueMember = nameof ( Inverter . sn ) ;
@@ -154,12 +182,16 @@ private void InverterComboBox_SelectedValueChanged(object sender, EventArgs e) =
154182 ? GoodWeStatus . InverterSelected
155183 : GoodWeStatus . Uninitialized ) ;
156184
185+
186+
157187 private void Credentials_TextChanged ( object sender , EventArgs e )
158188 {
159189 ResetComboBox ( plantComboBox ) ;
160190 ResetComboBox ( inverterComboBox ) ;
161191
162192 readDeviceInfoButton . Enabled = emailTextBox . TextLength > 0 && passwordTextBox . TextLength > 0 ;
193+
194+ _client = null ;
163195 }
164196
165197 private void SemsPortalLinkLabel_LinkClicked ( object sender , LinkLabelLinkClickedEventArgs e )
@@ -180,7 +212,7 @@ public async Task LoadConfigurationAsync(DataProviderConfiguration config)
180212 passwordTextBox . Text = config . Key ;
181213
182214 _optionsBackup = new CaseInsensitiveDictionary < string ? > ( config . Options ) ;
183-
215+
184216 await ReadDeviceInfoAsync ( ) ;
185217 }
186218
@@ -193,7 +225,7 @@ public DataProviderConfiguration GetConfiguration()
193225 {
194226 // Set Options before everything else.
195227 Options = _optionsBackup ?? new ( ) ,
196-
228+
197229 Account = emailTextBox . Text ,
198230 Description = plant ? . Description ,
199231 Key = passwordTextBox . Text ,
@@ -213,7 +245,7 @@ private void ResetComboBox(ComboBox comboBox)
213245 comboBox . SelectedItem = null ;
214246 comboBox . DataSource = null ;
215247 comboBox . Enabled = false ;
216-
248+
217249 SetStatus ( GoodWeStatus . Uninitialized ) ;
218250 }
219251 }
0 commit comments