1717 DOMAIN ,
1818 LOGGER ,
1919 SB_OPERATING_MODES ,
20+ SB_OPERATING_MODES_NUM ,
2021 SONNENBATTERIE_ISSUE_URL ,
2122)
2223
@@ -55,9 +56,7 @@ async def charge_battery(self, call: ServiceCall) -> ServiceResponse:
5556 power = 0
5657 # Make sure we have an sb2 object
5758 sb_conn = self ._get_sb_connection (call .data )
58- # await sb_conn.login()
5959 response = await sb_conn .sb2 .charge_battery (power )
60- # await sb_conn.logout()
6160 return {
6261 "charge" : response ,
6362 }
@@ -68,19 +67,15 @@ async def discharge_battery(self, call: ServiceCall) -> ServiceResponse:
6867 if power < 0 :
6968 power = 0
7069 sb_conn = self ._get_sb_connection (call .data )
71- # await sb_conn.login()
7270 response = await sb_conn .sb2 .discharge_battery (power )
73- # await sb_conn.logout()
7471 return {
7572 "discharge" : response ,
7673 }
7774
7875 async def set_battery_reserve (self , call : ServiceCall ) -> ServiceResponse :
7976 value = call .data .get (CONF_SERVICE_VALUE )
8077 sb_conn = self ._get_sb_connection (call .data )
81- # await sb_conn.login()
8278 response = int ((await sb_conn .sb2 .set_battery_reserve (value ))["EM_USOC" ])
83- # await sb_conn.logout()
8479 return {
8580 "battery_reserve" : response ,
8681 }
@@ -89,21 +84,25 @@ async def set_config_item(self, call: ServiceCall) -> ServiceResponse:
8984 item = call .data .get (CONF_SERVICE_ITEM )
9085 value = call .data .get (CONF_SERVICE_VALUE )
9186 sb_conn = self ._get_sb_connection (call .data )
92- # await sb_conn.login()
9387 response = await sb_conn .sb2 .set_config_item (item , value )
94- # await sb_conn.logout()
9588 return {
9689 "response" : response ,
9790 }
9891
9992 async def set_operating_mode (self , call : ServiceCall ) -> ServiceResponse :
10093 mode = SB_OPERATING_MODES .get (call .data .get ('mode' ))
10194 sb_conn = self ._get_sb_connection (call .data )
102- # await sb_conn.login()
10395 response = await sb_conn .set_operating_mode (mode )
104- # await sb_conn.logout()
10596 return {
106- "mode" : response ,
97+ "mode" : SB_OPERATING_MODES_NUM .get (str (response ), "UNKNOWN" )
98+ }
99+
100+ async def set_operating_mode_num (self , call : ServiceCall ) -> ServiceResponse :
101+ mode = call .data .get ('mode' )
102+ sb_conn = self ._get_sb_connection (call .data )
103+ response = await sb_conn .set_operating_mode (mode )
104+ return {
105+ "mode" : response
107106 }
108107
109108 async def set_tou_schedule (self , call : ServiceCall ) -> ServiceResponse :
@@ -122,38 +121,37 @@ async def set_tou_schedule(self, call: ServiceCall) -> ServiceResponse:
122121 raise HomeAssistantError (f"Schedule is not a valid schedule: '{ schedule } '" ) from t
123122
124123 sb_conn = self ._get_sb_connection (call .data )
125- # await sb_conn.login()
126124 response = await sb_conn .sb2 .set_tou_schedule_string (schedule )
127- # await sb_conn.logout()
128125 return {
129126 "schedule" : response ["EM_ToU_Schedule" ],
130127 }
131128
132129 # noinspection PyUnusedLocal
133130 async def get_tou_schedule (self , call : ServiceCall ) -> ServiceResponse :
134131 sb_conn = self ._get_sb_connection (call .data )
135- # await sb_conn.login()
136132 response = await sb_conn .sb2 .get_tou_schedule_string ()
137- # await sb_conn.logout()
138133 return {
139134 "schedule" : response ,
140135 }
141136
142137 # noinspection PyUnusedLocal
143138 async def get_battery_reserve (self , call : ServiceCall ) -> ServiceResponse :
144139 sb_conn = self ._get_sb_connection (call .data )
145- # await sb_conn.login()
146140 response = await sb_conn .sb2 .get_battery_reserve ()
147- # await sb_conn.logout()
148141 return {
149142 "backup_reserve" : response ,
150143 }
151144
152145 async def get_operating_mode (self , call : ServiceCall ) -> ServiceResponse :
153146 sb_conn = self ._get_sb_connection (call .data )
154- # await sb_conn.login()
155147 response = await sb_conn .sb2 .get_operating_mode ()
156- # await sb_conn.logout()
148+ return {
149+ "operating_mode" : SB_OPERATING_MODES_NUM .get (str (response ), "UNKNOWN" )
150+ }
151+
152+ async def get_operating_mode_num (self , call : ServiceCall ) -> ServiceResponse :
153+ sb_conn = self ._get_sb_connection (call .data )
154+ response = await sb_conn .sb2 .get_operating_mode ()
157155 return {
158156 "operating_mode" : response ,
159157 }
0 commit comments