Skip to content

Commit

Permalink
Make simulators return localhost address for info query (#1657)
Browse files Browse the repository at this point in the history
This will make it possible to directly use the data returned by the info
query for further uses.
  • Loading branch information
rytilahti authored Jan 8, 2023
1 parent 03880f0 commit ae35d8a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions miio/devtools/simulators/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from hashlib import md5


def create_info_response(model, mac):
def create_info_response(model, addr, mac):
"""Create a response for miIO.info call using the given model and mac."""
INFO_RESPONSE = {
"ap": {"bssid": "FF:FF:FF:FF:FF:FF", "rssi": -68, "ssid": "network"},
Expand All @@ -15,7 +15,7 @@ def create_info_response(model, mac):
"model": model,
"netif": {
"gw": "192.168.xxx.x",
"localIp": "192.168.xxx.x",
"localIp": addr,
"mask": "255.255.255.0",
},
"ot": "otu",
Expand Down
2 changes: 1 addition & 1 deletion miio/devtools/simulators/miiosimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async def main(dev):

_ = MiioSimulator(dev=dev, server=server)
mac = mac_from_model(dev._model)
server.add_method("miIO.info", create_info_response(dev._model, mac))
server.add_method("miIO.info", create_info_response(dev._model, "127.0.0.1", mac))

transport, proto = await server.start()

Expand Down
4 changes: 2 additions & 2 deletions miio/devtools/simulators/miotsimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ async def main(dev, model):

mac = mac_from_model(model)
simulator = MiotSimulator(device_model=dev)
server.add_method("miIO.info", create_info_response(model, mac))
server.add_method("miIO.info", create_info_response(model, "127.0.0.1", mac))
server.add_method("action", simulator.action)
server.add_method("get_properties", simulator.get_properties)
server.add_method("set_properties", simulator.set_properties)
Expand All @@ -215,7 +215,7 @@ def miot_simulator(file, model):
else:
cloud = MiotCloud()
# TODO: fix HACK
dev = SimulatedDeviceModel.parse_raw(cloud.get_model_schema(model))
dev = SimulatedDeviceModel.parse_obj(cloud.get_model_schema(model))

loop = asyncio.get_event_loop()
random.seed(1) # nosec
Expand Down

0 comments on commit ae35d8a

Please sign in to comment.