Skip to content

Serial Stream with HA and message delimiter #327

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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Betters some stuff for the linter
  • Loading branch information
jtkDvlp committed Jul 31, 2023
commit 944d2caa90e61d3b933874a67643f1b93190ef22
1 change: 0 additions & 1 deletion mqtt_io/home_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,3 @@ def hass_announce_stream(
json.dumps(stream_config).encode("utf8"),
retain=True,
)

14 changes: 9 additions & 5 deletions mqtt_io/modules/stream/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,22 @@ def setup_module(self) -> None:
self.ser.flushInput()

def read(self) -> Optional[bytes]:
if("delimiter" in self.config):
if("reset_before_read" in self.config):
if(self.config["reset_before_read"]):
data = None
if "delimiter" in self.config:
if "reset_before_read" in self.config:
if self.config["reset_before_read"]:
self.ser.reset_input_buffer()
data = self.ser.read_until(self.config["delimiter"].encode("utf-8"))
if data:
data = data[:-len(self.config["delimiter"])]
return data or None
else:
return self.ser.read(self.ser.in_waiting) or None
data = self.ser.read(self.ser.in_waiting) or None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtkDvlp I guess this is the problem:
read has to return Optinal[bytes], but in line 107 it may return "None" (or with the preset in line 98)


return data

def write(self, data: bytes) -> None:
if("delimiter" in self.config):
data = data + self.config["delimiter"].encode("utf-8")
self.ser.write(data)

def cleanup(self) -> None:
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy