Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aioecowitt/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ class EcoWittMapping:
"co2": EcoWittMapping("WH45 CO2", EcoWittSensorTypes.CO2_PPM),
"co2_24h": EcoWittMapping("WH45 CO2 24h average", EcoWittSensorTypes.CO2_PPM),
"co2_batt": EcoWittMapping("WH45 Battery", EcoWittSensorTypes.BATTERY_PERCENTAGE),
"batt_co2": EcoWittMapping("WH45 Battery", EcoWittSensorTypes.BATTERY_PERCENTAGE),
"leak_ch1": EcoWittMapping("Leak Detection 1", EcoWittSensorTypes.LEAK),
"leak_ch2": EcoWittMapping("Leak Detection 2", EcoWittSensorTypes.LEAK),
"leak_ch3": EcoWittMapping("Leak Detection 3", EcoWittSensorTypes.LEAK),
Expand Down
14 changes: 9 additions & 5 deletions aioecowitt/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,15 @@ def process_data(self, data: dict[str, str | float | int | None]) -> None:

async def handler(self, request: web.BaseRequest) -> web.Response:
"""AIOHTTP handler for the API."""
if request.method != "POST":
return web.Response(status=405)
if self.path is not None and request.path != self.path:
return web.Response(status=404)
data = await request.post()
if request.method == "GET":
# Ambient Weather variant
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain in the comment that this device is not doing a post request but a get

data = request.query
else:
if request.method != "POST":
return web.Response(status=405)
if self.path is not None and request.path != self.path:
return web.Response(status=404)
data = await request.post()
Comment on lines +98 to +103
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else:
if request.method != "POST":
return web.Response(status=405)
if self.path is not None and request.path != self.path:
return web.Response(status=404)
data = await request.post()
elif request.method != "POST":
return web.Response(status=405)
elif self.path is not None and request.path != self.path:
return web.Response(status=404)
else:
# regular POST request
data = await request.post()


# data is not a dict, it's a MultiDict
self.last_values[data["PASSKEY"]] = data.copy()
Expand Down
2 changes: 1 addition & 1 deletion aioecowitt/station.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def extract_station(data: dict[str, str]) -> EcoWittStation:
"""Extract station from data."""
station = data.pop("stationtype")
passkey = data.pop("PASSKEY")
model = data.pop("model")
model = data.pop("model", None)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe set something like "UNKNOWN" as default value for the model ?

frequence = data.pop("freq", None)

version = None
Expand Down