From 4c49af814c9be6780a0cc1a6a40a141a8773e60a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Feb 2026 00:09:24 +0000 Subject: [PATCH 1/8] Initial plan From 4ad9cadff76d203182db9a6f5fecb2a5f81dec0a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Feb 2026 00:13:42 +0000 Subject: [PATCH 2/8] Address PR review feedback: fix import, update key, remove AssetPlugin, migrate to pyproject.toml Co-authored-by: yutaka551 <1833002+yutaka551@users.noreply.github.com> --- octoprint_plotly_graph_lywsd03mmc/__init__.py | 69 +++++-------- pyproject.toml | 34 +++++++ setup.py | 96 +------------------ 3 files changed, 62 insertions(+), 137 deletions(-) create mode 100644 pyproject.toml diff --git a/octoprint_plotly_graph_lywsd03mmc/__init__.py b/octoprint_plotly_graph_lywsd03mmc/__init__.py index e978492..ec0c397 100644 --- a/octoprint_plotly_graph_lywsd03mmc/__init__.py +++ b/octoprint_plotly_graph_lywsd03mmc/__init__.py @@ -5,10 +5,11 @@ import threading import time +from lywsd03mmc import Lywsd03mmcClient + class PlotlyGraphLywsd03mmcPlugin( octoprint.plugin.SettingsPlugin, - octoprint.plugin.AssetPlugin, octoprint.plugin.TemplatePlugin, octoprint.plugin.StartupPlugin ): @@ -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): @@ -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 @@ -187,7 +168,7 @@ def get_temperature_data(self, comm, parsed_temps): def get_update_information(self): return dict( - plotlyGraphLywsd03mmc=dict( + plotly_graph_lywsd03mmc=dict( displayName="PlotlyGraph LYWSD03MMC Plugin", displayVersion=self._plugin_version, diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..e0ff1b7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,34 @@ +[build-system] +requires = ["setuptools>=68", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "OctoPrint-PlotlyGraph-LYWSD03MMC" +version = "0.1.0" +description = "Plugin to add LYWSD03MMC temperature and humidity sensor data to PlotlyTempGraph" +authors = [ + {name = "yutaka551", email = "yutaka551@users.noreply.github.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 = [ + "octoprint_plotly_graph_lywsd03mmc", + "octoprint_plotly_graph_lywsd03mmc.*" +] + +[project.entry-points."octoprint.plugin"] +plotly_graph_lywsd03mmc = "octoprint_plotly_graph_lywsd03mmc" + +[project.urls] +Homepage = "https://github.com/yutaka551/lywsd03mmc-plotly-graph" diff --git a/setup.py b/setup.py index 61de12d..0284329 100644 --- a/setup.py +++ b/setup.py @@ -1,95 +1,5 @@ # coding=utf-8 +import setuptools -# Do not forget to adjust the following variables to your own plugin. - -# The plugin's identifier, has to be unique -plugin_identifier = "plotly_graph_lywsd03mmc" - -# The plugin's python package, should be "octoprint_", has to be unique -plugin_package = "octoprint_plotly_graph_lywsd03mmc" - -# The plugin's human readable name. Can be overwritten within OctoPrint's internal data via __plugin_name__ in the -# plugin module -plugin_name = "OctoPrint-PlotlyGraph-LYWSD03MMC" - -# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "0.1.0" - -# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin -# module -plugin_description = """Plugin to add LYWSD03MMC temperature and humidity sensor data to PlotlyTempGraph""" - -# The plugin's author. Can be overwritten within OctoPrint's internal data via __plugin_author__ in the plugin module -plugin_author = "yutaka551" - -# The plugin's author's mail address. -plugin_author_email = "" - -# The plugin's homepage URL. Can be overwritten within OctoPrint's internal data via __plugin_url__ in the plugin module -plugin_url = "https://github.com/yutaka551/lywsd03mmc-plotly-graph" - -# The plugin's license. Can be overwritten within OctoPrint's internal data via __plugin_license__ in the plugin module -plugin_license = "AGPLv3" - -# Any additional requirements besides OctoPrint should be listed here -plugin_requires = ["lywsd03mmc>=0.1.0"] - -# -------------------------------------------------------------------------------------------------------------------- -# More advanced options that you usually shouldn't have to touch follow after this point -# -------------------------------------------------------------------------------------------------------------------- - -# Additional package data to install for this plugin. The subfolders "templates", "static" and "translations" will -# already be installed automatically if they exist. Note that if you add something here you'll also need to update -# MANIFEST.in to match to ensure that python setup.py sdist produces a source distribution that contains all your -# files. This is sadly due to how python's setup.py works, see also http://stackoverflow.com/a/14159430/2028598 -plugin_additional_data = [] - -# Any additional python packages you need to install with your plugin that are not contained in .* -plugin_additional_packages = [] - -# Any python packages within .* you do NOT want to install with your plugin -plugin_ignored_packages = [] - -# Additional parameters for the call to setuptools.setup. If your plugin wants to register additional entry points, -# define dependency links or other things like that, this is the place to go. Will be merged recursively with the -# default setup parameters as provided by octoprint_setuptools.create_plugin_setup_parameters using -# octoprint.util.dict_merge. -# -# Example: -# plugin_requires = ["someDependency==dev"] -# additional_setup_parameters = {"dependency_links": ["https://github.com/someUser/someRepo/archive/master.zip#egg=someDependency-dev"]} -additional_setup_parameters = {} - -######################################################################################################################## - -from setuptools import setup # noqa: E402 - -try: - import octoprint_setuptools -except ImportError: - print("Could not import OctoPrint's setuptools, are you sure you are running that under " - "the same python installation that OctoPrint is installed under?") - import sys - sys.exit(-1) - -setup_parameters = octoprint_setuptools.create_plugin_setup_parameters( - identifier=plugin_identifier, - package=plugin_package, - name=plugin_name, - version=plugin_version, - description=plugin_description, - author=plugin_author, - mail=plugin_author_email, - url=plugin_url, - license=plugin_license, - requires=plugin_requires, - additional_packages=plugin_additional_packages, - ignored_packages=plugin_ignored_packages, - additional_data=plugin_additional_data -) - -if len(additional_setup_parameters): - from octoprint.util import dict_merge - setup_parameters = dict_merge(setup_parameters, additional_setup_parameters) - -setup(**setup_parameters) +# we define the license string like this to be backwards compatible to setuptools<77 +setuptools.setup(license="MIT") From 09ff2085eccff87257f9664327ae5d57387fb72d Mon Sep 17 00:00:00 2001 From: yutaka551 Date: Mon, 23 Feb 2026 22:26:57 +0900 Subject: [PATCH 3/8] =?UTF-8?q?=E3=83=A1=E3=83=BC=E3=83=AB=E3=82=A2?= =?UTF-8?q?=E3=83=89=E3=83=AC=E3=82=B9=E3=82=92=E8=A8=AD=E5=AE=9A=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e0ff1b7..ea75a02 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ name = "OctoPrint-PlotlyGraph-LYWSD03MMC" version = "0.1.0" description = "Plugin to add LYWSD03MMC temperature and humidity sensor data to PlotlyTempGraph" authors = [ - {name = "yutaka551", email = "yutaka551@users.noreply.github.com"} + {name = "yutaka551", email = "yutaka551butaman@gmail.com"} ] readme = {file = "README.md", content-type = "text/markdown"} license = {text = "MIT"} From cc02fd006b3e9b2cc911b88d31e8e7353a63c27f Mon Sep 17 00:00:00 2001 From: yutaka551 Date: Mon, 23 Feb 2026 22:43:19 +0900 Subject: [PATCH 4/8] Fix project name in pyproject.toml and remove setup.py --- pyproject.toml | 4 ++-- setup.py | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) delete mode 100644 setup.py diff --git a/pyproject.toml b/pyproject.toml index ea75a02..deb2f57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,9 @@ [build-system] -requires = ["setuptools>=68", "wheel"] +requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" [project] -name = "OctoPrint-PlotlyGraph-LYWSD03MMC" +name = "lywsd03mmc-plotly-graph" version = "0.1.0" description = "Plugin to add LYWSD03MMC temperature and humidity sensor data to PlotlyTempGraph" authors = [ diff --git a/setup.py b/setup.py deleted file mode 100644 index 0284329..0000000 --- a/setup.py +++ /dev/null @@ -1,5 +0,0 @@ -# coding=utf-8 -import setuptools - -# we define the license string like this to be backwards compatible to setuptools<77 -setuptools.setup(license="MIT") From 7f879e10ec2a912bb1cdaaffc09cb9ca7250cd42 Mon Sep 17 00:00:00 2001 From: yutaka551 Date: Tue, 24 Feb 2026 22:46:52 +0900 Subject: [PATCH 5/8] Refactor project structure: update package names and add initial plugin implementation with settings template --- MANIFEST.in | 6 +++--- .../__init__.py | 0 .../templates/plotly_graph_lywsd03mmc_settings.jinja2 | 0 pyproject.toml | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) rename {octoprint_plotly_graph_lywsd03mmc => lywsd03mmc_plotly_graph}/__init__.py (100%) rename {octoprint_plotly_graph_lywsd03mmc => lywsd03mmc_plotly_graph}/templates/plotly_graph_lywsd03mmc_settings.jinja2 (100%) diff --git a/MANIFEST.in b/MANIFEST.in index 22ffa3f..41b43e5 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 * diff --git a/octoprint_plotly_graph_lywsd03mmc/__init__.py b/lywsd03mmc_plotly_graph/__init__.py similarity index 100% rename from octoprint_plotly_graph_lywsd03mmc/__init__.py rename to lywsd03mmc_plotly_graph/__init__.py diff --git a/octoprint_plotly_graph_lywsd03mmc/templates/plotly_graph_lywsd03mmc_settings.jinja2 b/lywsd03mmc_plotly_graph/templates/plotly_graph_lywsd03mmc_settings.jinja2 similarity index 100% rename from octoprint_plotly_graph_lywsd03mmc/templates/plotly_graph_lywsd03mmc_settings.jinja2 rename to lywsd03mmc_plotly_graph/templates/plotly_graph_lywsd03mmc_settings.jinja2 diff --git a/pyproject.toml b/pyproject.toml index deb2f57..953a659 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,12 +23,12 @@ include-package-data = true [tool.setuptools.packages.find] include = [ - "octoprint_plotly_graph_lywsd03mmc", - "octoprint_plotly_graph_lywsd03mmc.*" + "lywsd03mmc_plotly_graph", + "lywsd03mmc_plotly_graph.*" ] [project.entry-points."octoprint.plugin"] -plotly_graph_lywsd03mmc = "octoprint_plotly_graph_lywsd03mmc" +plotly_graph_lywsd03mmc = "lywsd03mmc_plotly_graph" [project.urls] Homepage = "https://github.com/yutaka551/lywsd03mmc-plotly-graph" From 410ed2240107e5a5177673c0f354bf02f6053114 Mon Sep 17 00:00:00 2001 From: yutaka551 Date: Tue, 24 Feb 2026 23:17:38 +0900 Subject: [PATCH 6/8] Fix plugin references in settings template for LYWSD03MMC sensor --- .../plotly_graph_lywsd03mmc_settings.jinja2 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lywsd03mmc_plotly_graph/templates/plotly_graph_lywsd03mmc_settings.jinja2 b/lywsd03mmc_plotly_graph/templates/plotly_graph_lywsd03mmc_settings.jinja2 index 06847b0..4be4764 100644 --- a/lywsd03mmc_plotly_graph/templates/plotly_graph_lywsd03mmc_settings.jinja2 +++ b/lywsd03mmc_plotly_graph/templates/plotly_graph_lywsd03mmc_settings.jinja2 @@ -4,7 +4,7 @@
- + {{ _('The Bluetooth MAC address of your LYWSD03MMC sensor. You can find this in the Xiaomi Home app or by running "sudo hcitool lescan".') }}
@@ -12,7 +12,7 @@
- + {{ _('How often to poll the sensor for new data (minimum 10 seconds recommended).') }}
@@ -22,7 +22,7 @@
{{ _('Show humidity readings in the graph.') }} @@ -32,7 +32,7 @@
{{ _('Show battery level in the graph.') }} @@ -44,7 +44,7 @@
- + {{ _('Label for temperature readings in the graph.') }}
@@ -52,7 +52,7 @@
- + {{ _('Label for humidity readings in the graph.') }}
@@ -60,7 +60,7 @@
- + {{ _('Label for battery level in the graph.') }}
From 4c7c94cc6ac87c12a688eb390c4154760a123c8e Mon Sep 17 00:00:00 2001 From: yutaka551 Date: Tue, 24 Feb 2026 23:22:53 +0900 Subject: [PATCH 7/8] Update plugin name for clarity in __init__.py --- lywsd03mmc_plotly_graph/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lywsd03mmc_plotly_graph/__init__.py b/lywsd03mmc_plotly_graph/__init__.py index ec0c397..644a8d8 100644 --- a/lywsd03mmc_plotly_graph/__init__.py +++ b/lywsd03mmc_plotly_graph/__init__.py @@ -184,7 +184,7 @@ def get_update_information(self): ) -__plugin_name__ = "PlotlyGraph LYWSD03MMC Sensor" +__plugin_name__ = "LYWSD03MMC Sensor Plugin for PlotlyGraph" __plugin_pythoncompat__ = ">=3.7,<4" __plugin_implementation__ = PlotlyGraphLywsd03mmcPlugin() __plugin_version__ = "0.1.0" From 9015341f3f2caf430401827284471d30e9a8b8c4 Mon Sep 17 00:00:00 2001 From: yutaka551 Date: Wed, 25 Feb 2026 00:31:06 +0900 Subject: [PATCH 8/8] Refactor plugin naming and settings template for consistency --- README.md | 2 +- lywsd03mmc_plotly_graph/__init__.py | 10 +++++----- ....jinja2 => lywsd03mmc_plotly_graph_settings.jinja2} | 0 pyproject.toml | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) rename lywsd03mmc_plotly_graph/templates/{plotly_graph_lywsd03mmc_settings.jinja2 => lywsd03mmc_plotly_graph_settings.jinja2} (100%) diff --git a/README.md b/README.md index fd3150a..edfed6b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# OctoPrint-PlotlyGraph-LYWSD03MMC +# lywsd03mmc-plotly-graph OctoPrint plugin to add LYWSD03MMC temperature and humidity sensor data to PlotlyTempGraph. diff --git a/lywsd03mmc_plotly_graph/__init__.py b/lywsd03mmc_plotly_graph/__init__.py index 644a8d8..d507f9f 100644 --- a/lywsd03mmc_plotly_graph/__init__.py +++ b/lywsd03mmc_plotly_graph/__init__.py @@ -8,7 +8,7 @@ from lywsd03mmc import Lywsd03mmcClient -class PlotlyGraphLywsd03mmcPlugin( +class Lywsd03mmcPlotlyGraphPlugin( octoprint.plugin.SettingsPlugin, octoprint.plugin.TemplatePlugin, octoprint.plugin.StartupPlugin @@ -168,8 +168,8 @@ def get_temperature_data(self, comm, parsed_temps): def get_update_information(self): return dict( - plotly_graph_lywsd03mmc=dict( - displayName="PlotlyGraph LYWSD03MMC Plugin", + lywsd03mmc_plotly_graph=dict( + displayName="lywsd03mmc-plotly-graph", displayVersion=self._plugin_version, # version check: github repository @@ -184,9 +184,9 @@ def get_update_information(self): ) -__plugin_name__ = "LYWSD03MMC Sensor Plugin for PlotlyGraph" +__plugin_name__ = "lywsd03mmc-plotly-graph" __plugin_pythoncompat__ = ">=3.7,<4" -__plugin_implementation__ = PlotlyGraphLywsd03mmcPlugin() +__plugin_implementation__ = Lywsd03mmcPlotlyGraphPlugin() __plugin_version__ = "0.1.0" __plugin_hooks__ = { diff --git a/lywsd03mmc_plotly_graph/templates/plotly_graph_lywsd03mmc_settings.jinja2 b/lywsd03mmc_plotly_graph/templates/lywsd03mmc_plotly_graph_settings.jinja2 similarity index 100% rename from lywsd03mmc_plotly_graph/templates/plotly_graph_lywsd03mmc_settings.jinja2 rename to lywsd03mmc_plotly_graph/templates/lywsd03mmc_plotly_graph_settings.jinja2 diff --git a/pyproject.toml b/pyproject.toml index 953a659..0247596 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ include = [ ] [project.entry-points."octoprint.plugin"] -plotly_graph_lywsd03mmc = "lywsd03mmc_plotly_graph" +lywsd03mmc_plotly_graph = "lywsd03mmc_plotly_graph" [project.urls] Homepage = "https://github.com/yutaka551/lywsd03mmc-plotly-graph"