Skip to content

Commit

Permalink
Replace pydantic in favor of mashumaro (#277)
Browse files Browse the repository at this point in the history
* Drop pydantic

* Drop pydantic from CI

* Relax mashumaro dependency
  • Loading branch information
Orhideous authored Mar 1, 2024
1 parent de62f2f commit 3fd3d75
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 181 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ jobs:
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
pydantic-version: ["1", "2"]
fail-fast: false

steps:
Expand Down Expand Up @@ -146,9 +145,6 @@ jobs:
- name: Install library
run: poetry install --no-interaction

- name: Install specific pydantic version
run: poetry add pydantic@^${{ matrix.pydantic-version }}

- name: Start Mosquitto
uses: namoshek/mosquitto-github-action@v1
with:
Expand Down
143 changes: 21 additions & 122 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ roombapy = "roombapy.cli:cli"
python = ">=3.10,<4.0"
orjson = ">=3.9.13"
paho-mqtt = "~1.6.1"
pydantic = ">=1"
mashumaro = {version = "^3.12"}
click = { version = "^8.1", optional = true }
tabulate = { version = "^0.9", optional = true }

Expand Down Expand Up @@ -74,7 +74,6 @@ docstring-code-format = true
follow_imports = "normal"
strict_optional = true
strict = true
plugins = ["pydantic.mypy"]
packages = ["roombapy", "tests"]

[tool.pydantic-mypy]
Expand Down
23 changes: 18 additions & 5 deletions roombapy/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import logging
import socket

from pydantic import ValidationError
from mashumaro import exceptions as merr
from orjson import JSONDecodeError

from roombapy.roomba_info import RoombaInfo
from roombapy.roomba_info import RoombaInfo, validate_hostname


class RoombaDiscovery:
Expand Down Expand Up @@ -93,10 +94,22 @@ def _decode_data(raw_response: bytes) -> RoombaInfo | None:
return None

try:
return RoombaInfo.parse_raw(data)
except ValidationError:
# Malformed json from robots
raw_info = RoombaInfo.from_json(data)
validate_hostname(raw_info.hostname)
except JSONDecodeError:
return None
except (
merr.MissingField,
merr.UnserializableDataError,
merr.InvalidFieldValue,
merr.MissingDiscriminatorError,
merr.SuitableVariantNotFoundError,
):
return None
except ValueError:
return None
else:
return raw_info


def _get_socket() -> socket.socket:
Expand Down
Loading

0 comments on commit 3fd3d75

Please sign in to comment.