44import aiohttp
55from yarl import URL
66
7- from . import _request as request
7+ from . import make_call
88from .constants import API , DEVICE_INFO , TEMPERATURE , LIGHT , FRONT_LED_GET , FRONT_LED_SET
99from .exceptions import DingzError
1010
@@ -28,38 +28,38 @@ def __init__(self, host: str, session: aiohttp.client.ClientSession = None) -> N
2828 async def get_device_info (self ) -> None :
2929 """Get the details from the dingz."""
3030 url = URL (self .uri ).join (URL (DEVICE_INFO ))
31- response = await request (self , uri = url )
31+ response = await make_call (self , uri = url )
3232 self ._device_details = response
3333
3434 async def get_temperature (self ) -> None :
3535 """Get the room temperature from the dingz."""
3636 url = URL (self .uri ).join (URL (TEMPERATURE ))
37- response = await request (self , uri = url )
37+ response = await make_call (self , uri = url )
3838 self ._temperature = response ["temperature" ]
3939
4040 async def get_light (self ) -> None :
4141 """Get the light details from the switch."""
4242 url = URL (self .uri ).join (URL (LIGHT ))
43- response = await request (self , uri = url )
43+ response = await make_call (self , uri = url )
4444 self ._intensity = response ["intensity" ]
4545 self ._day = response ["day" ]
4646
4747 async def enabled (self ) -> bool :
4848 """Return true if front LED is on."""
4949 url = URL (self .uri ).join (URL (FRONT_LED_GET ))
50- response = await request (self , uri = url )
50+ response = await make_call (self , uri = url )
5151 return bool (response ["on" ])
5252
5353 async def turn_on (self ) -> None :
5454 """Enable/turn on the front LED."""
5555 data = {"action" : "on" }
5656 url = URL (self .uri ).join (URL (FRONT_LED_SET ))
57- await request (self , uri = url , method = "POST" , data = data )
57+ await make_call (self , uri = url , method = "POST" , data = data )
5858
5959 async def turn_off (self ) -> None :
6060 """Disable/turn off the front LED."""
6161 url = URL (self .uri ).join (URL (FRONT_LED_SET ))
62- await request (self , uri = url , method = "POST" , data = {"action" : "off" })
62+ await make_call (self , uri = url , method = "POST" , data = {"action" : "off" })
6363
6464 @property
6565 def device_details (self ) -> str :
@@ -81,6 +81,8 @@ def intensity(self) -> float:
8181 """Return the current light intensity in lux."""
8282 return round (self ._intensity , 1 )
8383
84+ # See "Using Asyncio in Python" by Caleb Hattingh for implementation
85+ # details.
8486 async def close (self ) -> None :
8587 """Close an open client session."""
8688 if self ._session and self ._close_session :
0 commit comments