55from homeassistant import config_entries
66from homeassistant .config_entries import ConfigFlowResult
77from homeassistant .data_entry_flow import FlowResult
8+ from homeassistant .helpers .dispatcher import async_dispatcher_send
89from homeassistant .helpers .service_info import zeroconf
910from homeassistant .const import CONF_HOST , CONF_PORT
11+ from homeassistant .helpers .selector import selector
1012
1113from .const import DEFAULT_PORT , DOMAIN
1214
@@ -92,6 +94,12 @@ async def async_step_reconfigure(self, user_input: dict | None = None)->FlowResu
9294 entry = self .hass .config_entries .async_get_entry (self .context ["entry_id" ])
9395
9496 if user_input is not None :
97+ # @todo: better handling of mac association
98+ for key , role in user_input .items ():
99+ mac = key [33 :- 2 ]
100+ _LOGGER .debug (f"Sending { mac } , { role } to { DOMAIN } _update_role" )
101+ async_dispatcher_send (self .hass , f"{ DOMAIN } _update_role" ,
102+ mac , role ) # default role
95103 await self .hass .config_entries .async_reload (entry .entry_id )
96104 return self .async_abort (reason = "Powersensor role updates successful!" )
97105
@@ -100,19 +108,26 @@ async def async_step_reconfigure(self, user_input: dict | None = None)->FlowResu
100108 for sensor_mac in dispatcher .sensors :
101109 role = entry .data .get ('roles' , {}).get (sensor_mac , None )
102110 if not role :
103- sensor_roles [vol .Optional (f"device_type_ { sensor_mac } " )] = vol .In (
104- ["house-net" , "solar" , "water" , "appliance" , "none" ] # Your supported types
111+ sensor_roles [vol .Optional (f"Powersensor Sensor [Mac Address: { sensor_mac } ] " )] = vol .In (
112+ ["house-net" , "solar" , "water" , "appliance" , "none" ]
105113 )
106114 else :
107- sensor_roles [vol .Optional (f"device_type_{ sensor_mac } " , description = {"suggested_value" : role })] = vol .In (
108- ["house-net" , "solar" , "water" , "appliance" , "none" ] # Your supported types
109- )
115+ sensor_roles [vol .Optional (f"Powersensor Sensor [Mac Address: { sensor_mac } ]" , description = {"suggested_value" : role })] = selector ({
116+ "select" : {
117+ "options" : ["house-net" , "solar" , "water" , "appliance" , "none" ] ,
118+ "mode" : "dropdown"
119+ }
120+ })
121+
122+ # if not sensor_roles:
123+ # return self.async_abort(reason="no_sensors_found_without_roles")
110124
111125 return self .async_show_form (
112126 step_id = "reconfigure" ,
113127 data_schema = vol .Schema (sensor_roles ),
114128 description_placeholders = {
115- "device_count" : str (len (sensor_roles ))
129+ "device_count" : str (len (sensor_roles )),
130+ "docs_url" : "https://dius.github.io/homeassistant-powersensor/data.html#virtual-household"
116131 }
117132 )
118133
0 commit comments