77import importlib
88import json
99import os
10+ from typing import TYPE_CHECKING
1011
1112
1213with contextlib .suppress (ImportError ):
1314 from aiohttp import web
1415
16+ if TYPE_CHECKING :
17+ from aiohttp import web
18+
1519from pymodbus .datastore import ModbusServerContext , ModbusSimulatorContext
1620from pymodbus .datastore .simulator import Label
1721from pymodbus .logging import Log
@@ -137,7 +141,7 @@ def __init__(
137141 del server ["port" ]
138142 device = setup ["device_list" ][modbus_device ]
139143 self .datastore_context = ModbusSimulatorContext (
140- device , custom_actions_dict or {}
144+ device , custom_actions_dict or None
141145 )
142146 datastore = None
143147 if "device_id" in server :
@@ -251,7 +255,7 @@ async def stop(self):
251255 self .serving .set_result (True )
252256 await asyncio .sleep (0 )
253257
254- async def handle_html_static (self , request ): # pragma: no cover
258+ async def handle_html_static (self , request : web . Request ): # pragma: no cover
255259 """Handle static html."""
256260 if not (page := request .path [1 :]):
257261 page = "index.html"
@@ -264,7 +268,7 @@ async def handle_html_static(self, request): # pragma: no cover
264268 except (FileNotFoundError , IsADirectoryError ) as exc :
265269 raise web .HTTPNotFound (reason = "File not found" ) from exc
266270
267- async def handle_html (self , request ): # pragma: no cover
271+ async def handle_html (self , request : web . Request ): # pragma: no cover
268272 """Handle html."""
269273 page_type = request .path .split ("/" )[- 1 ]
270274 params = dict (request .query )
@@ -280,7 +284,7 @@ async def handle_html(self, request): # pragma: no cover
280284 new_page = self .generator_html [page_type ][1 ](params , html )
281285 return web .Response (text = new_page , content_type = "text/html" )
282286
283- async def handle_json (self , request ):
287+ async def handle_json (self , request : web . Request ):
284288 """Handle api registers."""
285289 command = request .path .split ("/" )[- 1 ]
286290 params = await request .json ()
0 commit comments