Skip to content

Commit 17ff141

Browse files
committed
Add some icons
1 parent cfb6807 commit 17ff141

File tree

5 files changed

+206
-70
lines changed

5 files changed

+206
-70
lines changed

custom_components/nemon_intex_swg/button.py

Lines changed: 165 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_e
2222
client = data["client"]
2323
coordinator = data["coordinator"]
2424

25-
async_add_entities([IntexSWGRebootButton(client, coordinator, entry)])
25+
async_add_entities([
26+
IntexSWGRebootButton(client, coordinator, entry),
27+
IntexSWGPowerOnButton(client, coordinator, entry),
28+
IntexSWGPowerOffButton(client, coordinator, entry),
29+
IntexSWGPowerStandbyButton(client, coordinator, entry),
30+
])
2631

2732
class IntexSWGRebootButton(CoordinatorEntity, ButtonEntity):
2833
def __init__(self, client, coordinator, entry):
2934
super().__init__(coordinator)
3035
self._client = client
3136
self._attr_name = "Reboot ESP32"
3237
self._attr_unique_id = f"{coordinator.name}_reboot"
38+
self._attr_icon = "mdi:restart"
3339

3440
# device_info
3541
host = entry.data.get(CONF_HOST)
@@ -41,7 +47,7 @@ def __init__(self, client, coordinator, entry):
4147
"manufacturer": DEVICE_MANUFACTURER,
4248
"model": DEVICE_MODEL,
4349
"connections": {("ip", host)}
44-
}
50+
}
4551

4652
async def async_press(self) -> None:
4753
url = f"http://{self._client._host}:{self._client._port}/api/v1/intex/swg/reboot"
@@ -58,3 +64,160 @@ async def async_press(self) -> None:
5864
def _refresh_cb(_):
5965
self.hass.async_create_task(self.coordinator.async_request_refresh())
6066
async_call_later(self.hass, 60, _refresh_cb)
67+
68+
class IntexSWGPowerOnButton(CoordinatorEntity, ButtonEntity):
69+
def __init__(self, client, coordinator, entry):
70+
super().__init__(coordinator)
71+
self._client = client
72+
self._attr_name = "Power ON"
73+
self._attr_unique_id = f"{coordinator.name}_power_on"
74+
75+
# Device info for the dashboard
76+
host = entry.data.get(CONF_HOST)
77+
port = entry.data.get(CONF_PORT)
78+
self._attr_device_info = {
79+
"identifiers": {(DOMAIN, entry.entry_id)},
80+
"name": f"{DEVICE_NAME} ({host}:{port})",
81+
"manufacturer": DEVICE_MANUFACTURER,
82+
"model": DEVICE_MODEL,
83+
"connections": {("ip", host)},
84+
}
85+
86+
@property
87+
def icon(self) -> str:
88+
"""Return a solid power icon if status == 'ON', else outline."""
89+
current_power = self._client.data.get("status", {}).get("power", "")
90+
return "mdi:radiobox-marked" if current_power == "ON" else "mdi:radiobox-blank"
91+
92+
@property
93+
def extra_state_attributes(self) -> dict[str, bool]:
94+
"""Provide an 'active' attribute for Lovelace usage."""
95+
current_power = self._client.data.get("status", {}).get("power", "")
96+
return {"active": current_power == "ON"}
97+
98+
async def async_press(self) -> None:
99+
url = f"http://{self._client._host}:{self._client._port}/api/v1/intex/swg"
100+
payload = {"data": {"power": "on"}}
101+
102+
_LOGGER.debug("POST Power ON: URL=%s, payload=%s", url, payload)
103+
104+
try:
105+
await self._client._session.post(url, json=payload)
106+
except Exception as err:
107+
_LOGGER.warning("Error sending Power ON: %s", err)
108+
109+
# Attempt to clear cache
110+
try:
111+
self._client.clear_cache()
112+
except Exception as err:
113+
_LOGGER.warning("Unable to clear cache: %s", err)
114+
115+
# Schedule a brief refresh so the UI reflects the new state
116+
async def _refresh_cb(_):
117+
self.hass.async_create_task(self.coordinator.async_request_refresh())
118+
119+
async_call_later(self.hass, 0.1, _refresh_cb)
120+
121+
class IntexSWGPowerOffButton(CoordinatorEntity, ButtonEntity):
122+
def __init__(self, client, coordinator, entry):
123+
super().__init__(coordinator)
124+
self._client = client
125+
self._attr_name = "Power OFF"
126+
self._attr_unique_id = f"{coordinator.name}_power_off"
127+
128+
# Device info for the dashboard
129+
host = entry.data.get(CONF_HOST)
130+
port = entry.data.get(CONF_PORT)
131+
self._attr_device_info = {
132+
"identifiers": {(DOMAIN, entry.entry_id)},
133+
"name": f"{DEVICE_NAME} ({host}:{port})",
134+
"manufacturer": DEVICE_MANUFACTURER,
135+
"model": DEVICE_MODEL,
136+
"connections": {("ip", host)},
137+
}
138+
139+
@property
140+
def icon(self) -> str:
141+
"""Return a solid power-off icon if status == 'OFF', else outline."""
142+
current_power = self._client.data.get("status", {}).get("power", "")
143+
return "mdi:radiobox-marked" if current_power == "OFF" else "mdi:radiobox-blank"
144+
145+
@property
146+
def extra_state_attributes(self) -> dict[str, bool]:
147+
"""Provide an 'active' attribute for Lovelace usage."""
148+
current_power = self._client.data.get("status", {}).get("power", "")
149+
return {"active": current_power == "OFF"}
150+
151+
async def async_press(self) -> None:
152+
url = f"http://{self._client._host}:{self._client._port}/api/v1/intex/swg"
153+
payload = {"data": {"power": "off"}}
154+
155+
_LOGGER.debug("POST Power OFF: URL=%s, payload=%s", url, payload)
156+
157+
try:
158+
await self._client._session.post(url, json=payload)
159+
except Exception as err:
160+
_LOGGER.warning("Error sending Power OFF: %s", err)
161+
162+
try:
163+
self._client.clear_cache()
164+
except Exception as err:
165+
_LOGGER.warning("Unable to clear cache: %s", err)
166+
167+
# Schedule a brief refresh so the UI reflects the new state
168+
async def _refresh_cb(_):
169+
self.hass.async_create_task(self.coordinator.async_request_refresh())
170+
171+
async_call_later(self.hass, 0.1, _refresh_cb)
172+
173+
class IntexSWGPowerStandbyButton(CoordinatorEntity, ButtonEntity):
174+
def __init__(self, client, coordinator, entry):
175+
super().__init__(coordinator)
176+
self._client = client
177+
self._attr_name = "Power STANDBY"
178+
self._attr_unique_id = f"{coordinator.name}_power_standby"
179+
180+
# Device info for the dashboard
181+
host = entry.data.get(CONF_HOST)
182+
port = entry.data.get(CONF_PORT)
183+
self._attr_device_info = {
184+
"identifiers": {(DOMAIN, entry.entry_id)},
185+
"name": f"{DEVICE_NAME} ({host}:{port})",
186+
"manufacturer": DEVICE_MANUFACTURER,
187+
"model": DEVICE_MODEL,
188+
"connections": {("ip", host)},
189+
}
190+
191+
@property
192+
def icon(self) -> str:
193+
"""Return a solid power-sleep icon if status == 'STANDBY', else outline."""
194+
current_power = self._client.data.get("status", {}).get("power", "")
195+
return "mdi:radiobox-marked" if current_power == "STANDBY" else "mdi:radiobox-blank"
196+
197+
@property
198+
def extra_state_attributes(self) -> dict[str, bool]:
199+
"""Provide an 'active' attribute for Lovelace usage."""
200+
current_power = self._client.data.get("status", {}).get("power", "")
201+
return {"active": current_power == "STANDBY"}
202+
203+
async def async_press(self) -> None:
204+
url = f"http://{self._client._host}:{self._client._port}/api/v1/intex/swg"
205+
payload = {"data": {"power": "standby"}}
206+
207+
_LOGGER.debug("POST Power STANDBY: URL=%s, payload=%s", url, payload)
208+
209+
try:
210+
await self._client._session.post(url, json=payload)
211+
except Exception as err:
212+
_LOGGER.warning("Error sending Power STANDBY: %s", err)
213+
214+
try:
215+
self._client.clear_cache()
216+
except Exception as err:
217+
_LOGGER.warning("Unable to clear cache: %s", err)
218+
219+
# Schedule a brief refresh so the UI reflects the new state
220+
async def _refresh_cb(_):
221+
self.hass.async_create_task(self.coordinator.async_request_refresh())
222+
223+
async_call_later(self.hass, 0.1, _refresh_cb)

custom_components/nemon_intex_swg/const.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@
1919
DEFAULT_REBOOT_ENABLED = False
2020
DEFAULT_REBOOT_INTERVAL = 720 # minutes (12 hours)
2121

22-
PLATFORMS = ["sensor", "select", "button"]
22+
PLATFORMS = ["sensor", "button"]
23+
24+
# https://pictogrammers.com/library/mdi/

custom_components/nemon_intex_swg/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"codeowners": ["@NemoN"],
55
"dependencies": [],
66
"documentation": "https://github.com/NemoN/ha-intex-swg",
7-
"version": "1.0.9",
7+
"version": "1.1.0",
88
"integration_type": "device",
99
"iot_class": "local_polling",
1010
"requirements": ["aiohttp>=3.8.0"],

custom_components/nemon_intex_swg/select.py

Lines changed: 0 additions & 66 deletions
This file was deleted.

custom_components/nemon_intex_swg/sensor.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ def __init__(self, client, coordinator, path, name, entry):
7373
self._attr_device_class = SensorDeviceClass.DURATION
7474
self._attr_state_class = SensorStateClass.MEASUREMENT
7575

76+
if self._path == ("display", "brightness"):
77+
self._attr_icon = "mdi:brightness-6"
78+
79+
if self._path == ("display", "current_code"):
80+
self._attr_icon = "mdi:counter"
81+
7682
# device_info
7783
host = entry.data.get(CONF_HOST)
7884
port = entry.data.get(CONF_PORT)
@@ -104,6 +110,36 @@ def __init__(self, client, coordinator, path, name, entry):
104110
self._attr_name = name
105111
self._attr_unique_id = f"{coordinator.name}_{'_'.join(path)}"
106112

113+
if self._path == ("status", "boost"):
114+
self._attr_icon = "mdi:lightning-bolt-circle"
115+
116+
if self._path == ("display", "status"):
117+
self._attr_icon = "mdi:monitor"
118+
119+
if self._path == ("status", "high_salt"):
120+
self._attr_icon = "mdi:alarm-light"
121+
122+
if self._path == ("status", "low_salt"):
123+
self._attr_icon = "mdi:alarm-light-outline"
124+
125+
if self._path == ("status", "pump_low_flow"):
126+
self._attr_icon = "mdi:waves"
127+
128+
if self._path == ("status", "o3_generation"):
129+
self._attr_icon = "mdi:water-check-outline"
130+
131+
if self._path == ("mode", "programming"):
132+
self._attr_icon = "mdi:timer-edit"
133+
134+
if self._path == ("mode", "working"):
135+
self._attr_icon = "mdi:run-fast"
136+
137+
if self._path == ("status", "service"):
138+
self._attr_icon = "mdi:account-wrench"
139+
140+
if self._path == ("status", "sleep"):
141+
self._attr_icon = "mdi:bed-clock"
142+
107143
# device_info
108144
host = entry.data.get(CONF_HOST)
109145
port = entry.data.get(CONF_PORT)
@@ -139,6 +175,7 @@ def __init__(self, coordinator, entry):
139175
#self._attr_unit_of_measurement = "W"
140176
self._attr_native_unit_of_measurement = "W"
141177
self._attr_state_class = SensorStateClass.MEASUREMENT
178+
self._attr_icon = "mdi:transmission-tower"
142179

143180
# device_info
144181
host = entry.data.get(CONF_HOST)

0 commit comments

Comments
 (0)