-
-
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.
Merge pull request #75 from mion00/feat/mqtt_input_text
feat: MQTT text entity
- Loading branch information
Showing
4 changed files
with
125 additions
and
4 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
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
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
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,40 @@ | ||
import random | ||
import string | ||
import pytest | ||
from ha_mqtt_discoverable import Settings | ||
from ha_mqtt_discoverable.sensors import Text, TextInfo | ||
|
||
|
||
@pytest.fixture() | ||
def text() -> Text: | ||
mqtt_settings = Settings.MQTT(host="localhost") | ||
text_info = TextInfo(name="test", min=5) | ||
settings = Settings(mqtt=mqtt_settings, entity=text_info) | ||
# Define empty callback | ||
return Text(settings, lambda *_: None) | ||
|
||
|
||
def test_required_config(): | ||
mqtt_settings = Settings.MQTT(host="localhost") | ||
text_info = TextInfo(name="test") | ||
settings = Settings(mqtt=mqtt_settings, entity=text_info) | ||
# Define empty callback | ||
text = Text(settings, lambda *_: None) | ||
assert text is not None | ||
|
||
|
||
def test_set_text(text: Text): | ||
text.set_text("this is as test") | ||
|
||
|
||
def test_too_short_string(text: Text): | ||
with pytest.raises(RuntimeError): | ||
text.set_text("t") | ||
|
||
|
||
def test_too_long_string(text: Text): | ||
length = 500 | ||
letters = string.ascii_lowercase | ||
random_string = "".join(random.choice(letters) for i in range(length)) | ||
with pytest.raises(RuntimeError): | ||
text.set_text(random_string) |