Skip to content

Commit 9e8b5a0

Browse files
committed
fix http get bug and mDNS function
1 parent 0f87072 commit 9e8b5a0

16 files changed

+31
-24
lines changed

custom_components/bituopmd/__init__.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
_LOGGER = logging.getLogger(__name__)
1111

12-
PLATFORMS = [Platform.BUTTON, Platform.SWITCH]
12+
PLATFORMS = [Platform.SENSOR, Platform.BUTTON, Platform.SWITCH]
1313

1414
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
1515
"""Set up BituoPMD integration from a config entry."""
@@ -18,7 +18,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
1818

1919
host_ip = entry.data[CONF_HOST_IP]
2020
_LOGGER.info("Setting up BituoPMD integration for %s", host_ip)
21-
21+
2222
# Initialize the data dictionary for this entry
2323
hass.data[DOMAIN][entry.entry_id] = {}
2424

@@ -40,12 +40,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
4040
)
4141

4242
# Forward the setup to the sensor platforms
43-
try:
44-
await hass.config_entries.async_forward_entry_setup(entry, Platform.SENSOR)
45-
except ConfigEntryNotReady as e:
46-
_LOGGER.error("Error setting up sensor platform for BituoPMD: %s", e)
47-
raise ConfigEntryNotReady from e
48-
4943
try:
5044
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
5145
except ConfigEntryNotReady as e:
4.19 KB
Binary file not shown.
7.54 KB
Binary file not shown.
Binary file not shown.
250 Bytes
Binary file not shown.
5.5 KB
Binary file not shown.
23.4 KB
Binary file not shown.
8.16 KB
Binary file not shown.

custom_components/bituopmd/button.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import requests
33
from datetime import timedelta
4+
import asyncio
45
from homeassistant.components.button import ButtonEntity
56
from homeassistant.helpers.entity import DeviceInfo
67
from homeassistant.helpers.update_coordinator import (
@@ -26,7 +27,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
2627
device_info = {
2728
"model": data.get("productModel") or data.get("ProductModel", "Unknown Model"),
2829
"fw_version": data.get("FWVersion") or data.get("fwVersion", "Unknown"),
29-
"manufacturer": data.get("Manufactor", "Unknown"),
30+
"manufacturer": "BITUO TECHNIK",
3031
"mcu_version": data.get("MCUVersion", "Unknown"),
3132
}
3233
except Exception as e:
@@ -38,7 +39,15 @@ async def async_setup_entry(hass, entry, async_add_entities):
3839
"mcu_version": "Unknown",
3940
}
4041

41-
sensor_coordinator = hass.data[DOMAIN][entry.entry_id]['sensor_coordinator']
42+
for _ in range(50):
43+
try:
44+
sensor_coordinator = hass.data[DOMAIN][entry.entry_id]['sensor_coordinator']
45+
break
46+
except (KeyError, AttributeError):
47+
await asyncio.sleep(0.1)
48+
else:
49+
_LOGGER.error("sensor_coordinator not found for entry %s after waiting", entry.entry_id)
50+
return
4251

4352
buttons = [
4453
DataRefreshButton(sensor_coordinator, host_ip, device_info["model"], device_info["fw_version"], device_info["manufacturer"], device_info["mcu_version"]),

custom_components/bituopmd/config_flow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async def async_step_zeroconf(self, discovery_info: ZeroconfServiceInfo):
4444
self.host = discovery_info.host
4545
self.name = discovery_info.name.split(".")[0]
4646

47-
if "bituotechnik" not in self.name.lower():
47+
if "energysensor" not in self.name.lower():
4848
return self.async_abort(reason="not_bituotechnik_device")
4949

5050
existing_entries = self._async_current_entries()
@@ -233,7 +233,7 @@ def _on_service_state_change(self, zeroconf, service_type, name, state_change):
233233
info = zeroconf.get_service_info(service_type, name)
234234
if info:
235235
address = socket.inet_ntoa(info.addresses[0])
236-
if "bituotechnik" in name.lower(): # Ensure the device name contains 'bituotechnik'
236+
if "energysensor" in name.lower(): # Ensure the device name contains 'bituotechnik'
237237
# Check if the device is already in the list or already configured
238238
existing_entries = self._async_current_entries()
239239

0 commit comments

Comments
 (0)