Skip to content

Commit a1b76e0

Browse files
committed
Minor improvements
1 parent 8effbce commit a1b76e0

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

Taipower/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ async def run(l):
443443

444444
collections.deque(
445445
map(
446-
lambda x, y: setattr(y[0], y[1], x) if not isinstance(x, RuntimeError) else errors.append(x),
446+
lambda x, y: setattr(y[0], y[1], x) if not isinstance(x, Exception) else errors.append(x),
447447
asyncio.run(run(async_functions)),
448448
return_storages
449449
)

docs/source/example.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Example
2+
3+
## API
4+
5+
1. Import API and define credential informaiton.
6+
7+
```
8+
from Taipower.api import TaipowerAPI
9+
10+
# Fill out your Jci Hitachi email address, password, and electric number.
11+
ACCOUNT = "0987654321"
12+
PASSWORD = "password"
13+
ELECTRICNUMBER = "00xxxxxxxx"
14+
```
15+
16+
2. Login to API and get info.
17+
18+
```
19+
# Login
20+
api = TaipowerAPI(ACCOUNT, PASSWORD, ELECTRICNUMBER)
21+
api.login()
22+
23+
# Check ami, ami bill, and bill records
24+
ami = api.meters[ELECTRICNUMBER].ami
25+
ami_bill = api.meters[ELECTRICNUMBER].ami_bill
26+
bill_records = api.meters[ELECTRICNUMBER].bill_records
27+
```
28+
29+
4. Refresh status.
30+
31+
```
32+
# Check the updated device status
33+
api.refresh_status()
34+
```
35+
36+
The python script can be found [here](https://github.com/qqaatw/libtaipower/blob/main/example.py).

example.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from Taipower.api import TaipowerAPI
2+
3+
# Fill out your Jci Hitachi email address, password, and electric number.
4+
ACCOUNT = "0987654321"
5+
PASSWORD = "password"
6+
ELECTRICNUMBER = "00xxxxxxxx"
7+
8+
def main():
9+
# Login
10+
api = TaipowerAPI(ACCOUNT, PASSWORD, ELECTRICNUMBER)
11+
api.login()
12+
13+
# Check ami, ami bill, and bill records
14+
ami = api.meters[ELECTRICNUMBER].ami
15+
ami_bill = api.meters[ELECTRICNUMBER].ami_bill
16+
bill_records = api.meters[ELECTRICNUMBER].bill_records
17+
18+
# Refresh status
19+
api.refresh_status()
20+
21+
if __name__ == "__main__":
22+
main()

tests/test_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ async def mock(client=None):
165165
}
166166
return "OK", return_value
167167

168-
async def mock_failed(time_period, dt, electric_number, client=None):
168+
async def mock_failed(client=None):
169169
return "Not OK", {}
170170

171171
mock_login.return_value = ("OK", "")

0 commit comments

Comments
 (0)