Skip to content

Commit 6fc09a5

Browse files
committed
Improve model strins
1 parent 1d10b82 commit 6fc09a5

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

custom_components/weatherlink/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
9292
]
9393
):
9494
sensors.append(sensor)
95-
# todo Remove
96-
# print(f"{sensor['parent_device_id']} {sensor['sensor_type']}")
9795
hass.data[DOMAIN][entry.entry_id]["sensors_metadata"] = sensors
9896
coordinator = await get_coordinator(hass, entry)
9997
if not coordinator.last_update_success:

custom_components/weatherlink/binary_sensor.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from homeassistant.helpers.entity_platform import AddEntitiesCallback
1717
from homeassistant.helpers.update_coordinator import CoordinatorEntity
1818

19-
from . import get_coordinator
19+
from . import SENSOR_TYPE_VUE_AND_VANTAGE_PRO, get_coordinator
2020
from .const import (
2121
CONF_API_VERSION,
2222
CONFIG_URL,
@@ -175,13 +175,25 @@ def generate_model(self):
175175
model: str = self.hass.data[DOMAIN][self.entry.entry_id]["station_data"][
176176
"stations"
177177
][0].get("product_number")
178-
if model == "6555":
179-
return f"WeatherLinkIP {model}"
180-
if model.startswith("6100"):
181-
return f"WeatherLink Live {model}"
182-
if model.startswith("6313"):
183-
return f"WeatherLink Console {model}"
184-
return "WeatherLink"
178+
for sensor in self.hass.data[DOMAIN][self.entry.entry_id][
179+
"sensors_metadata"
180+
]:
181+
if (
182+
sensor["sensor_type"] in SENSOR_TYPE_VUE_AND_VANTAGE_PRO
183+
and sensor["tx_id"] is None
184+
or sensor["tx_id"] == self.tx_id
185+
):
186+
product_name = sensor["product_name"]
187+
break
188+
gateway_type = "WeatherLink"
189+
if model == "6555":
190+
gateway_type = f"WLIP {model}"
191+
if model.startswith("6100"):
192+
gateway_type = f"WLL {model}"
193+
if model.startswith("6313"):
194+
gateway_type = f"WLC {model}"
195+
196+
return f"{gateway_type} / {product_name}" if self.tx_id == 1 else product_name
185197

186198
@property
187199
def is_on(self):

custom_components/weatherlink/sensor.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from homeassistant.helpers.entity_platform import AddEntitiesCallback
3030
from homeassistant.helpers.update_coordinator import CoordinatorEntity
3131

32-
from . import get_coordinator
32+
from . import SENSOR_TYPE_VUE_AND_VANTAGE_PRO, get_coordinator
3333
from .const import (
3434
CONF_API_VERSION,
3535
CONFIG_URL,
@@ -459,13 +459,25 @@ def generate_model(self):
459459
model: str = self.hass.data[DOMAIN][self.entry.entry_id]["station_data"][
460460
"stations"
461461
][0].get("product_number")
462-
if model == "6555":
463-
return f"WeatherLinkIP {model}"
464-
if model.startswith("6100"):
465-
return f"WeatherLink Live {model}"
466-
if model.startswith("6313"):
467-
return f"WeatherLink Console {model}"
468-
return "WeatherLink"
462+
for sensor in self.hass.data[DOMAIN][self.entry.entry_id][
463+
"sensors_metadata"
464+
]:
465+
if (
466+
sensor["sensor_type"] in SENSOR_TYPE_VUE_AND_VANTAGE_PRO
467+
and sensor["tx_id"] is None
468+
or sensor["tx_id"] == self.tx_id
469+
):
470+
product_name = sensor["product_name"]
471+
break
472+
gateway_type = "WeatherLink"
473+
if model == "6555":
474+
gateway_type = f"WLIP {model}"
475+
if model.startswith("6100"):
476+
gateway_type = f"WLL {model}"
477+
if model.startswith("6313"):
478+
gateway_type = f"WLC {model}"
479+
480+
return f"{gateway_type} / {product_name}" if self.tx_id == 1 else product_name
469481

470482
@property
471483
def native_value(self):

0 commit comments

Comments
 (0)