Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include README.md
include requirements.txt
recursive-include octoprint_plotly_graph_lywsd03mmc/templates *
recursive-include octoprint_plotly_graph_lywsd03mmc/static *
recursive-include octoprint_plotly_graph_lywsd03mmc/translations *
recursive-include lywsd03mmc_plotly_graph/templates *
recursive-include lywsd03mmc_plotly_graph/static *
recursive-include lywsd03mmc_plotly_graph/translations *
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# OctoPrint-PlotlyGraph-LYWSD03MMC
# lywsd03mmc-plotly-graph


OctoPrint plugin to add LYWSD03MMC temperature and humidity sensor data to PlotlyTempGraph.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import threading
import time

from lywsd03mmc import Lywsd03mmcClient

class PlotlyGraphLywsd03mmcPlugin(

class Lywsd03mmcPlotlyGraphPlugin(
octoprint.plugin.SettingsPlugin,
octoprint.plugin.AssetPlugin,
octoprint.plugin.TemplatePlugin,
octoprint.plugin.StartupPlugin
):
Expand Down Expand Up @@ -46,15 +47,6 @@ def on_after_startup(self):
else:
self._logger.warning("No MAC address configured. Please configure the sensor MAC address in settings.")

# AssetPlugin mixin

def get_assets(self):
return dict(
js=[],
css=[],
less=[]
)

# TemplatePlugin mixin

def get_template_configs(self):
Expand Down Expand Up @@ -102,45 +94,34 @@ def _read_sensor(self):
self._battery = None
return

try:
# Import here to avoid issues if the library isn't installed
from lywsd03mmc import Lywsd03mmcClient

# Create or reuse client
if self._client is None:
self._logger.info("Connecting to sensor at %s", mac_address)
try:
self._client = Lywsd03mmcClient(mac_address)
except Exception as e:
self._logger.error("Failed to connect to sensor: %s", e)
# Reset sensor data when connection fails
self._temperature = None
self._humidity = None
self._battery = None
return

# Read sensor data
# Create or reuse client
if self._client is None:
self._logger.info("Connecting to sensor at %s", mac_address)
try:
data = self._client.data
self._temperature = data.temperature
self._humidity = data.humidity
self._battery = data.battery
self._last_update = time.time()

self._logger.debug("Sensor data - Temp: %.1f°C, Humidity: %d%%, Battery: %d%%",
self._temperature, self._humidity, self._battery)
self._client = Lywsd03mmcClient(mac_address)
except Exception as e:
self._logger.error("Failed to read sensor data: %s", e)
# Reset client on data read error to force reconnection on next attempt
self._client = None
# Reset sensor data when read fails
self._logger.error("Failed to connect to sensor: %s", e)
# Reset sensor data when connection fails
self._temperature = None
self._humidity = None
self._battery = None
return

except ImportError:
self._logger.error("lywsd03mmc library not installed. Please install it: pip install lywsd03mmc")
# Reset sensor data when library is not available
# Read sensor data
try:
data = self._client.data
self._temperature = data.temperature
self._humidity = data.humidity
self._battery = data.battery
self._last_update = time.time()

self._logger.debug("Sensor data - Temp: %.1f°C, Humidity: %d%%, Battery: %d%%",
self._temperature, self._humidity, self._battery)
except Exception as e:
self._logger.error("Failed to read sensor data: %s", e)
# Reset client on data read error to force reconnection on next attempt
self._client = None
# Reset sensor data when read fails
self._temperature = None
self._humidity = None
self._battery = None
Expand Down Expand Up @@ -187,8 +168,8 @@ def get_temperature_data(self, comm, parsed_temps):

def get_update_information(self):
return dict(
plotlyGraphLywsd03mmc=dict(
displayName="PlotlyGraph LYWSD03MMC Plugin",
lywsd03mmc_plotly_graph=dict(
displayName="lywsd03mmc-plotly-graph",
displayVersion=self._plugin_version,

# version check: github repository
Expand All @@ -203,9 +184,9 @@ def get_update_information(self):
)


__plugin_name__ = "PlotlyGraph LYWSD03MMC Sensor"
__plugin_name__ = "lywsd03mmc-plotly-graph"
__plugin_pythoncompat__ = ">=3.7,<4"
__plugin_implementation__ = PlotlyGraphLywsd03mmcPlugin()
__plugin_implementation__ = Lywsd03mmcPlotlyGraphPlugin()
__plugin_version__ = "0.1.0"

__plugin_hooks__ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<div class="control-group">
<label class="control-label">{{ _('Sensor MAC Address') }}</label>
<div class="controls">
<input type="text" class="input-block-level" data-bind="value: settings.plugins.plotly_graph_lywsd03mmc.mac_address" placeholder="A4:C1:38:12:34:56">
<input type="text" class="input-block-level" data-bind="value: settings.plugins.lywsd03mmc_plotly_graph.mac_address" placeholder="A4:C1:38:12:34:56">
<span class="help-block">{{ _('The Bluetooth MAC address of your LYWSD03MMC sensor. You can find this in the Xiaomi Home app or by running "sudo hcitool lescan".') }}</span>
</div>
</div>

<div class="control-group">
<label class="control-label">{{ _('Update Interval (seconds)') }}</label>
<div class="controls">
<input type="number" class="input-block-level" data-bind="value: settings.plugins.plotly_graph_lywsd03mmc.update_interval" min="10" max="3600">
<input type="number" class="input-block-level" data-bind="value: settings.plugins.lywsd03mmc_plotly_graph.update_interval" min="10" max="3600">
<span class="help-block">{{ _('How often to poll the sensor for new data (minimum 10 seconds recommended).') }}</span>
</div>
</div>
Expand All @@ -22,7 +22,7 @@
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.plotly_graph_lywsd03mmc.display_humidity">
<input type="checkbox" data-bind="checked: settings.plugins.lywsd03mmc_plotly_graph.display_humidity">
{{ _('Display Humidity') }}
</label>
<span class="help-block">{{ _('Show humidity readings in the graph.') }}</span>
Expand All @@ -32,7 +32,7 @@
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.plotly_graph_lywsd03mmc.display_battery">
<input type="checkbox" data-bind="checked: settings.plugins.lywsd03mmc_plotly_graph.display_battery">
{{ _('Display Battery Level') }}
</label>
<span class="help-block">{{ _('Show battery level in the graph.') }}</span>
Expand All @@ -44,23 +44,23 @@
<div class="control-group">
<label class="control-label">{{ _('Temperature Label') }}</label>
<div class="controls">
<input type="text" class="input-block-level" data-bind="value: settings.plugins.plotly_graph_lywsd03mmc.temp_label">
<input type="text" class="input-block-level" data-bind="value: settings.plugins.lywsd03mmc_plotly_graph.temp_label">
<span class="help-block">{{ _('Label for temperature readings in the graph.') }}</span>
</div>
</div>

<div class="control-group">
<label class="control-label">{{ _('Humidity Label') }}</label>
<div class="controls">
<input type="text" class="input-block-level" data-bind="value: settings.plugins.plotly_graph_lywsd03mmc.humidity_label">
<input type="text" class="input-block-level" data-bind="value: settings.plugins.lywsd03mmc_plotly_graph.humidity_label">
<span class="help-block">{{ _('Label for humidity readings in the graph.') }}</span>
</div>
</div>

<div class="control-group">
<label class="control-label">{{ _('Battery Label') }}</label>
<div class="controls">
<input type="text" class="input-block-level" data-bind="value: settings.plugins.plotly_graph_lywsd03mmc.battery_label">
<input type="text" class="input-block-level" data-bind="value: settings.plugins.lywsd03mmc_plotly_graph.battery_label">
<span class="help-block">{{ _('Label for battery level in the graph.') }}</span>
</div>
</div>
Expand Down
34 changes: 34 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "lywsd03mmc-plotly-graph"
version = "0.1.0"
description = "Plugin to add LYWSD03MMC temperature and humidity sensor data to PlotlyTempGraph"
authors = [
{name = "yutaka551", email = "yutaka551butaman@gmail.com"}
]
readme = {file = "README.md", content-type = "text/markdown"}
license = {text = "MIT"}

requires-python = ">=3.7, <4"

dependencies = [
"lywsd03mmc>=0.1.0"
]

[tool.setuptools]
include-package-data = true

[tool.setuptools.packages.find]
include = [
"lywsd03mmc_plotly_graph",
"lywsd03mmc_plotly_graph.*"
]

[project.entry-points."octoprint.plugin"]
lywsd03mmc_plotly_graph = "lywsd03mmc_plotly_graph"

[project.urls]
Homepage = "https://github.com/yutaka551/lywsd03mmc-plotly-graph"
95 changes: 0 additions & 95 deletions setup.py

This file was deleted.