88from homeassistant .helpers .restore_state import RestoreEntity
99from homeassistant .helpers .update_coordinator import CoordinatorEntity
1010
11- from .const import DOMAIN , POWER_ICON , ECU_REBOOT_ICON
11+ from .const import DOMAIN , POWER_ICON
1212from .gui_helpers import pers_notification
1313
1414_LOGGER = logging .getLogger (__name__ )
@@ -22,7 +22,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
2222 for uid , inv_data in inverters .items ():
2323 switches .append (APsystemsECUInverterSwitch (coordinator , ecu , uid , inv_data ))
2424 switches .append (APsystemsZeroExportSwitch (coordinator , ecu ))
25- switches .append (RebootECUSwitch (ecu ))
2625 switches .append (APsystemsAllInvertersSwitch (coordinator , ecu ))
2726 async_add_entities (switches )
2827
@@ -198,78 +197,3 @@ async def async_turn_off(self, **kwargs):
198197 self .async_write_ha_state ()
199198 except Exception as e :
200199 _LOGGER .error ("Failed to turn off zero export: %s" , e )
201-
202- class RebootECUSwitch (SwitchEntity , RestoreEntity ):
203- """Momentary switch to reboot the ECU."""
204-
205- def __init__ (self , ecu ):
206- """Initialize the switch."""
207- self ._ecu = ecu
208- self ._state = False
209- self ._name = f"ECU { ecu .ecu .ecu_id } Reboot Switch"
210- self ._unique_id = f"ECU_{ ecu .ecu .ecu_id } _reboot_switch"
211-
212- @property
213- def unique_id (self ):
214- """Return the unique ID of the switch."""
215- return self ._unique_id
216-
217- @property
218- def name (self ):
219- """Return the name of the switch."""
220- return self ._name
221-
222- @property
223- def icon (self ):
224- """Return the icon to use in the UI."""
225- return ECU_REBOOT_ICON
226-
227- @property
228- def device_info (self ):
229- """Return the device info for the ECU."""
230- return {
231- "identifiers" : {
232- (DOMAIN , f"ecu_{ self ._ecu .ecu .ecu_id } " ),
233- },
234- "name" : f"ECU { self ._ecu .ecu .ecu_id } " ,
235- "manufacturer" : "APsystems" ,
236- "model" : self ._ecu .ecu .firmware ,
237- "sw_version" : self ._ecu .ecu .firmware ,
238- }
239-
240- @property
241- def entity_category (self ):
242- """Return the category of the entity."""
243- return EntityCategory .DIAGNOSTIC
244-
245- @property
246- def is_on (self ):
247- """Return the state of the switch."""
248- return self ._state
249-
250- async def async_turn_on (self , ** kwargs ):
251- """Reboot the ECU."""
252- self ._state = True
253- self .async_write_ha_state ()
254-
255- try :
256- await self ._ecu .reboot_ecu ()
257- pers_notification (
258- self .hass ,
259- f"Rebooted ECU { self ._ecu .ecu .ecu_id } "
260- )
261- except Exception as e :
262- _LOGGER .error ("Failed to reboot ECU: %s" , e )
263- pers_notification (
264- self .hass ,
265- f"Failed to reboot ECU: { e } "
266- )
267-
268- # Turn off the switch after 2 seconds
269- await asyncio .sleep (2 )
270- self ._state = False
271- self .async_write_ha_state ()
272-
273- async def async_turn_off (self , ** kwargs ):
274- """Handle turning the switch off."""
275- pass # Momentary switch, no manual turn-off
0 commit comments