Skip to content

Commit

Permalink
feat: support for breez and pro devices (#14)
Browse files Browse the repository at this point in the history
* test: improve coverage

* test: update pyproject.toml for tests

* test: add device properties for testing

* test: add coverage for mock clients

* test: mock client handles disconnect properly

* test: states are copied in mock clients

* docs: add supported devices, update usage

---------

Co-authored-by: github-actions <github-actions@github.com>
  • Loading branch information
AustinBrunkhorst and github-actions authored Sep 10, 2023
1 parent e95d3db commit 3b823c8
Show file tree
Hide file tree
Showing 22 changed files with 3,587 additions and 1,762 deletions.
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,32 @@ Install this via pip (or your favourite package manager):

`pip install pysnooz`

## Supported devices

- [SNOOZ Original](https://getsnooz.com/products/snooz-white-noise-machine)
- [SNOOZ Pro](https://getsnooz.com/products/snooz-pro-white-noise-machine)
- [Breez](https://getsnooz.com/products/snooz-breez-smart-bedroom-fan-sound-machine)

## Usage

```python
import asyncio
from datetime import timedelta
from bleak.backends.client import BLEDevice
from pysnooz.device import SnoozDevice
from pysnooz.commands import SnoozCommandResultStatus, turn_on, turn_off, set_volume
from home_assistant_bluetooth import BluetoothServiceInfo
from pysnooz.device import (
SnoozAdvertisementData,
SnoozDevice,
SnoozCommandResultStatus,
turn_on,
turn_off,
set_volume
)

# found with discovery
ble_device = BLEDevice(...)
token = "deadbeef"
device_info = BluetoothServiceInfo(...)
advertisement = parse_snooz_advertisement(device_info)

device = SnoozDevice(ble_device, token, asyncio.get_event_loop())
device = SnoozDevice(device_info, advertisement, asyncio.get_event_loop())

# optionally specify a volume to set before turning on
await device.async_execute_command(turn_on(volume=100))
Expand Down
184 changes: 94 additions & 90 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,90 +1,94 @@
[tool.poetry]
name = "pysnooz"
version = "0.8.6"
description = "Control SNOOZ white noise machines."
authors = ["Austin Brunkhorst <pysnooz@alb.dev>"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/AustinBrunkhorst/pysnooz"
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Natural Language :: English",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries",
]
packages = [{ include = "pysnooz", from = "src" }]

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/AustinBrunkhorst/pysnooz/issues"
"Changelog" = "https://github.com/AustinBrunkhorst/pysnooz/blob/main/CHANGELOG.md"

[tool.poetry.dependencies]
python = "^3.10"
home-assistant-bluetooth = ">=1.3.0"
bluetooth-sensor-state-data = ">=1.5.0"
bleak-retry-connector = ">=3.0.2"
bleak = ">=0.20.2"
Events = "^0.4"
transitions = "^0.8.11"

[tool.poetry.dev-dependencies]
pytest = "^7.0"
pytest-cov = "^4.0"
pytest-asyncio = "^0.19.0"
freezegun = "^1.2.2"
pytest-mock = "^3.8.2"
pandas = "^1.4.3"
autopep8 = "^1.7.0"
flake8 = "^5.0.4"

[tool.semantic_release]
branch = "main"
version_toml = ["pyproject.toml:tool.poetry.version"]
version_variables = ["src/pysnooz/__init__.py:__version__"]
build_command = "pip install poetry && poetry build"

[tool.pytest.ini_options]
addopts = "-v -Wdefault --cov=pysnooz --cov-report=term-missing:skip-covered"
pythonpath = ["src"]
log_cli = true
log_cli_level = "DEBUG"

[tool.coverage.run]
branch = true

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"@overload",
"if TYPE_CHECKING",
"raise NotImplementedError",
]

[tool.isort]
profile = "black"
known_first_party = ["pysnooz", "tests"]

[tool.mypy]
check_untyped_defs = true
disallow_any_generics = true
disallow_incomplete_defs = true
disallow_untyped_defs = true
mypy_path = "src/"
no_implicit_optional = true
show_error_codes = true
warn_unreachable = true
warn_unused_ignores = true
exclude = ['setup.py']

[[tool.mypy.overrides]]
module = "tests.*"
allow_untyped_defs = true

[[tool.mypy.overrides]]
module = "freezegun.*"
ignore_missing_imports = true

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "pysnooz"
version = "0.8.6"
description = "Control SNOOZ white noise machines."
authors = ["Austin Brunkhorst <pysnooz@alb.dev>"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/AustinBrunkhorst/pysnooz"
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Natural Language :: English",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries",
]
packages = [{ include = "pysnooz", from = "src" }]

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/AustinBrunkhorst/pysnooz/issues"
"Changelog" = "https://github.com/AustinBrunkhorst/pysnooz/blob/main/CHANGELOG.md"

[tool.poetry.dependencies]
python = "^3.10"
home-assistant-bluetooth = ">=1.3.0"
bluetooth-sensor-state-data = ">=1.5.0"
bleak-retry-connector = ">=3.0.2"
bleak = ">=0.20.2"
Events = "^0.4"
transitions = "^0.8.11"

[tool.poetry.dev-dependencies]
pytest = "^7.0"
pytest-cov = "^4.0"
pytest-asyncio = "^0.19.0"
freezegun = "^1.2.2"
pytest-mock = "^3.8.2"
pandas = "^1.4.3"
autopep8 = "^1.7.0"
flake8 = "^5.0.4"

[tool.semantic_release]
branch = "main"
version_toml = ["pyproject.toml:tool.poetry.version"]
version_variables = ["src/pysnooz/__init__.py:__version__"]
build_command = "pip install poetry && poetry build"

[tool.pytest.ini_options]
addopts = "-v -Wdefault --cov=pysnooz --cov-report=term-missing:skip-covered"
pythonpath = ["src"]
log_cli = true
log_cli_level = "DEBUG"
markers = [
"model",
]

[tool.coverage.run]
branch = true

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"@abstract",
"@overload",
"if TYPE_CHECKING",
"raise NotImplementedError",
]

[tool.isort]
profile = "black"
known_first_party = ["pysnooz", "tests"]

[tool.mypy]
check_untyped_defs = true
disallow_any_generics = true
disallow_incomplete_defs = true
disallow_untyped_defs = true
mypy_path = "src/"
no_implicit_optional = true
show_error_codes = true
warn_unreachable = true
warn_unused_ignores = true
exclude = ['setup.py']

[[tool.mypy.overrides]]
module = "tests.*"
allow_untyped_defs = true

[[tool.mypy.overrides]]
module = "freezegun.*"
ignore_missing_imports = true

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
53 changes: 52 additions & 1 deletion src/pysnooz/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,52 @@
__version__ = "0.8.6"
from .advertisement import (
SnoozAdvertisementData,
get_device_display_name,
parse_snooz_advertisement,
)
from .commands import (
SnoozCommandResult,
SnoozCommandResultStatus,
get_device_info,
set_auto_temp_enabled,
set_fan_speed,
set_temp_target,
set_volume,
turn_fan_off,
turn_fan_on,
turn_off,
turn_on,
)
from .device import SnoozCommandData, SnoozDevice
from .model import (
SnoozDeviceCharacteristicData,
SnoozDeviceModel,
SnoozDeviceState,
SnoozFirmwareVersion,
UnknownSnoozState,
)

__version__ = "0.8.6"

__all__ = [
"SnoozDeviceModel",
"SnoozFirmwareVersion",
"SnoozDevice",
"SnoozDeviceState",
"SnoozDeviceCharacteristicData",
"UnknownSnoozState",
"SnoozCommandData",
"SnoozCommandResult",
"SnoozCommandResultStatus",
"SnoozAdvertisementData",
"parse_snooz_advertisement",
"get_device_display_name",
"get_device_info",
"turn_on",
"turn_off",
"set_volume",
"turn_fan_on",
"turn_fan_off",
"set_fan_speed",
"set_auto_temp_enabled",
"set_temp_target",
]
Loading

0 comments on commit 3b823c8

Please sign in to comment.