@@ -140,24 +140,31 @@ async def connect(device_config: Dict[str, Any], api, loop=None):
140
140
LOGGER .error ('Unable to find ZiGate using auto mode' )
141
141
raise serial .SerialException ("Unable to find Zigate using auto mode" )
142
142
143
- port = os .path .realpath (port )
144
- if re .match (r"/dev/(tty(S|AMA)|serial)\d+" , port ):
145
- # Suppose pizigate on /dev/ttyAMAx or /dev/serialx
146
- await set_pizigate_running_mode ()
147
- if re .match (r"/dev/ttyUSB\d+" , port ):
148
- device = next (serial .tools .list_ports .grep (port ))
149
- if device .manufacturer == 'FTDI' : # Suppose zigate din /dev/ttyUSBx
150
- await set_zigatedin_running_mode ()
151
-
152
- _ , protocol = await serial_asyncio .create_serial_connection (
153
- loop ,
154
- lambda : protocol ,
155
- url = port ,
156
- baudrate = ZIGATE_BAUDRATE ,
157
- parity = serial .PARITY_NONE ,
158
- stopbits = serial .STOPBITS_ONE ,
159
- xonxoff = False ,
160
- )
143
+ if port .startswith ('socket://' ):
144
+ host , port = port .split (':' , 1 ) # 192.168.x.y:9999
145
+ port = int (port )
146
+ _ , protocol = await loop .create_connection (
147
+ lambda : protocol ,
148
+ host , port )
149
+ else :
150
+ port = os .path .realpath (port )
151
+ if re .match (r"/dev/(tty(S|AMA)|serial)\d+" , port ):
152
+ # Suppose pizigate on /dev/ttyAMAx or /dev/serialx
153
+ await set_pizigate_running_mode ()
154
+ if re .match (r"/dev/ttyUSB\d+" , port ):
155
+ device = next (serial .tools .list_ports .grep (port ))
156
+ if device .manufacturer == 'FTDI' : # Suppose zigate din /dev/ttyUSBx
157
+ await set_zigatedin_running_mode ()
158
+
159
+ _ , protocol = await serial_asyncio .create_serial_connection (
160
+ loop ,
161
+ lambda : protocol ,
162
+ url = port ,
163
+ baudrate = ZIGATE_BAUDRATE ,
164
+ parity = serial .PARITY_NONE ,
165
+ stopbits = serial .STOPBITS_ONE ,
166
+ xonxoff = False ,
167
+ )
161
168
162
169
await connected_future
163
170
0 commit comments