Skip to content

Commit 0c48d6a

Browse files
Copilotemiltin
andcommitted
Use 'type' instead of 'sxl' for determining proxy type
Separates concerns by using 'type' field for proxy determination while keeping 'sxl' for schema validation as suggested in review feedback. Co-authored-by: emiltin <66034+emiltin@users.noreply.github.com>
1 parent d682be5 commit 0c48d6a

6 files changed

Lines changed: 20 additions & 17 deletions

File tree

config/supervisor.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
port: 12111
22
guest:
33
sxl: tlc
4+
type: tlc
45
intervals:
56
timer: 0.1
67
watchdog: 0.1

documentation/classes_and_modules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Proxy has to child classes: SiteProxy and SupervisorProxy.
5555
A SiteProxy represents a connection from a Supervisor to a remote Site. It provides methods for sending commands and requesting status from the connected site.
5656

5757
### TrafficLightControllerProxy
58-
A TrafficLightControllerProxy is a specialized SiteProxy for Traffic Light Controller (TLC) sites. It provides high-level methods for common TLC operations like setting signal plans and fetching current plan status. The supervisor automatically creates TLCProxy instances when TLC sites connect (based on the site configuration having `sxl: 'tlc'`).
58+
A TrafficLightControllerProxy is a specialized SiteProxy for Traffic Light Controller (TLC) sites. It provides high-level methods for common TLC operations like setting signal plans and fetching current plan status. The supervisor automatically creates TLCProxy instances when TLC sites connect (based on the site configuration having `type: 'tlc'`).
5959

6060
### SiteProxy
6161
A connection to a remote Site.

documentation/tlc_proxy.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ The TLC proxy provides convenient methods that abstract away the low-level RSMP
1515

1616
## Automatic Detection
1717

18-
When a TLC site connects to a supervisor, the supervisor automatically detects that it's a TLC based on the site configuration (`sxl: 'tlc'`) and creates a `TrafficLightControllerProxy` instead of a generic `SiteProxy`.
18+
When a TLC site connects to a supervisor, the supervisor automatically detects that it's a TLC based on the site configuration (`type: 'tlc'`) and creates a `TrafficLightControllerProxy` instead of a generic `SiteProxy`.
1919

2020
This happens in the supervisor's connection handling:
2121

2222
```ruby
2323
# In supervisor configuration
2424
supervisor_settings = {
2525
'sites' => {
26-
'TLC001' => { 'sxl' => 'tlc' }
26+
'TLC001' => { 'sxl' => 'tlc', 'type' => 'tlc' }
2727
},
28-
'guest' => { 'sxl' => 'tlc' } # For unknown TLC sites
28+
'guest' => { 'sxl' => 'tlc', 'type' => 'tlc' } # For unknown TLC sites
2929
}
3030

3131
# When TLC001 connects, supervisor creates TLCProxy automatically

lib/rsmp/supervisor.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def handle_supervisor_settings supervisor_settings
2323
'ips' => 'all',
2424
'guest' => {
2525
'sxl' => 'tlc',
26+
'type' => 'tlc',
2627
'intervals' => {
2728
'timer' => 1,
2829
'watchdog' => 1
@@ -178,7 +179,7 @@ def accept_connection socket, info
178179

179180
# Determine the appropriate proxy type based on site settings
180181
site_settings = check_site_id id
181-
if site_settings && site_settings['sxl'] == 'tlc'
182+
if site_settings && site_settings['type'] == 'tlc'
182183
proxy = TLC::TrafficLightControllerProxy.new settings.merge(site_id:id)
183184
else
184185
proxy = SiteProxy.new settings.merge(site_id:id)

spec/supervisor_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ def connect task, core_versions:, sxl_version:
170170
supervisor_settings: {
171171
'port' => 13113,
172172
'sites' => {
173-
'TLC001' => { 'sxl' => 'tlc' }
173+
'TLC001' => { 'sxl' => 'tlc', 'type' => 'tlc' }
174174
},
175-
'guest' => { 'sxl' => 'tlc' }
175+
'guest' => { 'sxl' => 'tlc', 'type' => 'tlc' }
176176
},
177177
log_settings: log_settings
178178
)
@@ -193,7 +193,7 @@ def connect task, core_versions:, sxl_version:
193193
}
194194

195195
# Test the logic that would be used in accept_connection
196-
if site_settings && site_settings['sxl'] == 'tlc'
196+
if site_settings && site_settings['type'] == 'tlc'
197197
proxy = RSMP::TLC::TrafficLightControllerProxy.new settings.merge(site_id: 'TLC001')
198198
else
199199
proxy = RSMP::SiteProxy.new settings.merge(site_id: 'TLC001')
@@ -208,7 +208,7 @@ def connect task, core_versions:, sxl_version:
208208
# Test the core proxy creation logic directly
209209
# Create a basic supervisor for the test
210210
test_supervisor = RSMP::Supervisor.new(
211-
supervisor_settings: { 'port' => 13115, 'guest' => { 'sxl' => 'tlc' } },
211+
supervisor_settings: { 'port' => 13115, 'guest' => { 'sxl' => 'tlc', 'type' => 'tlc' } },
212212
log_settings: log_settings
213213
)
214214

@@ -225,18 +225,18 @@ def connect task, core_versions:, sxl_version:
225225
}
226226

227227
# Test with TLC-like settings
228-
tlc_site_settings = { 'sxl' => 'tlc' }
229-
non_tlc_site_settings = { 'sxl' => 'core' }
228+
tlc_site_settings = { 'sxl' => 'tlc', 'type' => 'tlc' }
229+
non_tlc_site_settings = { 'sxl' => 'core', 'type' => 'core' }
230230

231231
# Test TLC proxy creation
232-
if tlc_site_settings && tlc_site_settings['sxl'] == 'tlc'
232+
if tlc_site_settings && tlc_site_settings['type'] == 'tlc'
233233
tlc_proxy = RSMP::TLC::TrafficLightControllerProxy.new settings.merge(site_id: 'TLC001')
234234
else
235235
tlc_proxy = RSMP::SiteProxy.new settings.merge(site_id: 'TLC001')
236236
end
237237

238238
# Test non-TLC proxy creation
239-
if non_tlc_site_settings && non_tlc_site_settings['sxl'] == 'tlc'
239+
if non_tlc_site_settings && non_tlc_site_settings['type'] == 'tlc'
240240
non_tlc_proxy = RSMP::TLC::TrafficLightControllerProxy.new settings.merge(site_id: 'OTHER001')
241241
else
242242
non_tlc_proxy = RSMP::SiteProxy.new settings.merge(site_id: 'OTHER001')
@@ -271,7 +271,7 @@ def connect task, core_versions:, sxl_version:
271271
}
272272

273273
# Test the logic for non-TLC sites
274-
if site_settings && site_settings['sxl'] == 'tlc'
274+
if site_settings && site_settings['type'] == 'tlc'
275275
proxy = RSMP::TLC::TrafficLightControllerProxy.new settings.merge(site_id: 'OTHER001')
276276
else
277277
proxy = RSMP::SiteProxy.new settings.merge(site_id: 'OTHER001')

spec/tlc/traffic_light_controller_proxy_integration_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
{
2929
'port' => port,
3030
'sites' => {
31-
site_id => { 'sxl' => 'tlc' }
31+
site_id => { 'sxl' => 'tlc', 'type' => 'tlc' }
3232
},
3333
'guest' => {
34-
'sxl' => 'tlc' # Use valid schema type
34+
'sxl' => 'tlc', # Use valid schema type
35+
'type' => 'tlc' # Proxy type
3536
}
3637
}
3738
}
@@ -122,7 +123,7 @@
122123
AsyncRSpec.async do |task|
123124
# Create a supervisor with TLC configuration to avoid schema errors
124125
supervisor_without_connection = RSMP::Supervisor.new(
125-
supervisor_settings: { 'port' => 13113, 'guest' => { 'sxl' => 'tlc' } },
126+
supervisor_settings: { 'port' => 13113, 'guest' => { 'sxl' => 'tlc', 'type' => 'tlc' } },
126127
log_settings: log_settings
127128
)
128129

0 commit comments

Comments
 (0)