@@ -52,6 +52,7 @@ type SDS200Client interface {
5252 SetDateTime (daylightSaving int , t time.Time ) error
5353 GetLocationRange () (sds200.LocationRange , error )
5454 SetLocationRange (lat , lon , rng string ) error
55+ GetList (listType string , index ... int ) (sds200.XMLNode , error )
5556 GetChargeStatus () (sds200.ChargeStatus , error )
5657 KeepAlive () error
5758 PowerOff () error
@@ -501,7 +502,7 @@ func (s *ScannerSession) executeIntent(intent ControlIntent, params ControlParam
501502 }
502503 return s .resyncAfterScopeChange (client )
503504 case IntentSetSystemQuickKeys :
504- if err := validateQuickKeyTag ("favorites quick key " , params .ScopeFavoritesTag ); err != nil {
505+ if err := validateFavoritesIndex ("favorites index " , params .ScopeFavoritesTag ); err != nil {
505506 return err
506507 }
507508 values , err := validateQuickKeyValues (params .QuickKeyValues , 100 , "system quick keys" )
@@ -514,10 +515,10 @@ func (s *ScannerSession) executeIntent(intent ControlIntent, params ControlParam
514515 }
515516 return s .resyncAfterScopeChange (client )
516517 case IntentSetDepartmentQuickKeys :
517- if err := validateQuickKeyTag ("favorites quick key " , params .ScopeFavoritesTag ); err != nil {
518+ if err := validateFavoritesIndex ("favorites index " , params .ScopeFavoritesTag ); err != nil {
518519 return err
519520 }
520- if err := validateQuickKeyTag ("system quick key" , params .ScopeSystemTag ); err != nil {
521+ if err := validateQuickKeySlot ("system quick key" , params .ScopeSystemTag ); err != nil {
521522 return err
522523 }
523524 values , err := validateQuickKeyValues (params .QuickKeyValues , 100 , "department quick keys" )
@@ -731,14 +732,58 @@ func (s *ScannerSession) executeIntent(intent ControlIntent, params ControlParam
731732 }
732733}
733734
735+ func (s * ScannerSession ) ReadScannerList (listType string , index int ) ([]gui.ListItem , error ) {
736+ if s == nil {
737+ return nil , errors .New ("scanner session unavailable" )
738+ }
739+ listType = strings .TrimSpace (listType )
740+ if listType == "" {
741+ return nil , errors .New ("list type is required" )
742+ }
743+
744+ s .mu .RLock ()
745+ client := s .client
746+ s .mu .RUnlock ()
747+ if client == nil {
748+ return nil , errors .New ("scanner client unavailable" )
749+ }
750+
751+ var node sds200.XMLNode
752+ var err error
753+ if index >= 0 {
754+ node , err = client .GetList (listType , index )
755+ } else {
756+ node , err = client .GetList (listType )
757+ }
758+ if err != nil {
759+ return nil , err
760+ }
761+
762+ items := make ([]gui.ListItem , 0 , len (node .Children ))
763+ for _ , child := range node .Children {
764+ if strings .EqualFold (child .XMLName .Local , "Footer" ) {
765+ continue
766+ }
767+ attrs := make (map [string ]string , len (child .Attrs ))
768+ for k , v := range child .Attrs {
769+ attrs [k ] = v
770+ }
771+ items = append (items , gui.ListItem {
772+ Tag : child .XMLName .Local ,
773+ Attrs : attrs ,
774+ })
775+ }
776+ return items , nil
777+ }
778+
734779func (s * ScannerSession ) ReadScanScope (favoritesTag , systemTag int ) (gui.ScanScopeSnapshot , error ) {
735780 if s == nil {
736781 return gui.ScanScopeSnapshot {}, errors .New ("scanner session unavailable" )
737782 }
738- if err := validateQuickKeyTag ("favorites quick key " , favoritesTag ); err != nil {
783+ if err := validateFavoritesIndex ("favorites index " , favoritesTag ); err != nil {
739784 return gui.ScanScopeSnapshot {}, err
740785 }
741- if err := validateQuickKeyTag ("system quick key" , systemTag ); err != nil {
786+ if err := validateQuickKeySlot ("system quick key" , systemTag ); err != nil {
742787 return gui.ScanScopeSnapshot {}, err
743788 }
744789
@@ -753,13 +798,15 @@ func (s *ScannerSession) ReadScanScope(favoritesTag, systemTag int) (gui.ScanSco
753798 if err != nil {
754799 return gui.ScanScopeSnapshot {}, err
755800 }
756- systemState , err := client .GetSystemQuickKeys (favoritesTag )
757- if err != nil {
758- return gui.ScanScopeSnapshot {}, err
801+ // SQK/DQK may fail for special favorites lists (e.g. Full Database) that
802+ // use sentinel index values. Treat failures as empty quick key states.
803+ var systemState sds200.QuickKeyState
804+ if sqk , sqkErr := client .GetSystemQuickKeys (favoritesTag ); sqkErr == nil {
805+ systemState = sqk
759806 }
760- departmentState , err := client . GetDepartmentQuickKeys ( favoritesTag , systemTag )
761- if err ! = nil {
762- return gui. ScanScopeSnapshot {}, err
807+ var departmentState sds200. QuickKeyState
808+ if dqk , dqkErr := client . GetDepartmentQuickKeys ( favoritesTag , systemTag ); dqkErr = = nil {
809+ departmentState = dqk
763810 }
764811 serviceTypes , err := client .GetServiceTypes ()
765812 if err != nil {
@@ -835,7 +882,14 @@ func applyLocationToExpert(expert *ExpertRuntimeState, loc sds200.LocationRange)
835882 )
836883}
837884
838- func validateQuickKeyTag (name string , value int ) error {
885+ func validateFavoritesIndex (name string , value int ) error {
886+ if value < 0 {
887+ return fmt .Errorf ("%s must be >= 0 (got %d)" , name , value )
888+ }
889+ return nil
890+ }
891+
892+ func validateQuickKeySlot (name string , value int ) error {
839893 if value < 0 || value > 99 {
840894 return fmt .Errorf ("%s must be in range 0-99 (got %d)" , name , value )
841895 }
0 commit comments