Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace pydantic in favor of mashumaro #277

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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
144 changes: 22 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", extras = ["orjson"]}
Orhideous marked this conversation as resolved.
Show resolved Hide resolved
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