-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a2a540
commit c0a01e2
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import random | ||
import string | ||
import pytest | ||
from ha_mqtt_discoverable import Settings | ||
from ha_mqtt_discoverable.sensors import Number, NumberInfo | ||
|
||
|
||
@pytest.fixture() | ||
def number() -> Number: | ||
mqtt_settings = Settings.MQTT(host="localhost") | ||
number_info = NumberInfo(name="test", min=5.0, max=90.0) | ||
settings = Settings(mqtt=mqtt_settings, entity=number_info) | ||
# Define empty callback | ||
return Number(settings, lambda *_: None) | ||
|
||
|
||
def test_required_config(): | ||
mqtt_settings = Settings.MQTT(host="localhost") | ||
number_info = NumberInfo(name="test") | ||
settings = Settings(mqtt=mqtt_settings, entity=number_info) | ||
# Define empty callback | ||
number = Number(settings, lambda *_: None) | ||
assert number is not None | ||
|
||
|
||
def test_set_number(number: Number): | ||
number.set_number(42.0) | ||
|
||
|
||
def test_number_too_small(number: Number): | ||
with pytest.raises(RuntimeError): | ||
number.set_number(4.0) | ||
|
||
|
||
def test_number_too_large(number: Number): | ||
with pytest.raises(RuntimeError): | ||
number.set_number(91.0) |