File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -84,17 +84,18 @@ func NewEMapsProvider(logger *slog.Logger) (Provider, error) {
8484 zones := make (map [string ]string , len (zoneData ))
8585
8686 for zone , details := range zoneData {
87- // Check for countryName
88- var compoundName string
87+ // Build compound name from countryName and zoneName
88+ var parts [] string
8989
90- for _ , name := range []string {"countryName" , "zoneName" } {
91- if n , ok := details [name ]; ok {
92- compoundName = fmt .Sprintf ("%s %s" , compoundName , n )
93- }
90+ if details .CountryName != "" {
91+ parts = append (parts , details .CountryName )
92+ }
93+
94+ if details .ZoneName != "" {
95+ parts = append (parts , details .ZoneName )
9496 }
95- // Trim white spaces
96- compoundName = strings .TrimSpace (compoundName )
97- zones [zone ] = compoundName
97+
98+ zones [zone ] = strings .Join (parts , " " )
9899 }
99100
100101 e := & emapsProvider {
Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ func TestEMapsDataProviderError(t *testing.T) {
106106
107107func TestNewEMapsProvider (t * testing.T ) {
108108 // Start test server
109- expected := eMapsZonesResponse {"FR" : map [ string ] string { "zoneName" : "France" }}
109+ expected := eMapsZonesResponse {"FR" : eMapsZoneDetails { ZoneName : "France" }}
110110
111111 server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
112112 err := json .NewEncoder (w ).Encode (& expected )
Original file line number Diff line number Diff line change @@ -136,8 +136,20 @@ type CountryCode struct {
136136 IsoCode []CountryCodeFields `json:"3166-1"`
137137}
138138
139+ // eMapsZoneDetails represents the details of a zone from the Electricity Maps API.
140+ type eMapsZoneDetails struct {
141+ ZoneName string `json:"zoneName"`
142+ CountryName string `json:"countryName"`
143+ ZoneKey string `json:"zoneKey"`
144+ CountryCode string `json:"countryCode"`
145+ ZoneParentKey * string `json:"zoneParentKey"`
146+ SubZoneKeys []string `json:"subZoneKeys"`
147+ IsCommerciallyAvailable bool `json:"isCommerciallyAvailable"`
148+ Tier * string `json:"tier"`
149+ }
150+
139151// Electricity Maps zones response signature.
140- type eMapsZonesResponse map [string ]map [ string ] string
152+ type eMapsZonesResponse map [string ]eMapsZoneDetails
141153
142154// Electricity Maps carbon intensity response signature.
143155type eMapsCarbonIntensityResponse struct {
You can’t perform that action at this time.
0 commit comments