Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pet_weight in Puramax is set only the very first time of a day #30

Open
override80 opened this issue Dec 3, 2022 · 2 comments · Fixed by #35
Open

pet_weight in Puramax is set only the very first time of a day #30

override80 opened this issue Dec 3, 2022 · 2 comments · Fixed by #35

Comments

@override80
Copy link

override80 commented Dec 3, 2022

Hi,

I just noticed that the sensor sensor.t4_XXXXXXXX_pet_weight is evaluated only once a day. This means that if my cats enter the litter multiple times, i just get the weight of the pet entering the litter first after midnight.

Is it something that can be fixed? How can I help?

Screenshot_20221203-091134

@override80
Copy link
Author

override80 commented Dec 3, 2022

Well, apparently the problem lies in the parsing of the response returned by the /t4/getDeviceRecord api call. It in fact returns a json with a "result" array. Every object of this array with eventType 10 has a content.petWeight value, but the sensor slways reports the first result

{
	'result': [{
		'deviceId': xxxxxxx,
		'eventType': 10,
		'timestamp': 1670026756,
		'content': {
			'timeIn': 1670026644,
			'timeOut': 1670026756,
			'autoClear': 5,
			'interval': 5,
			'petWeight': 4042
		},
		'enumEventType': 'pet_out',
		'userId': 'xxxxxxxx',
		'subContent': []
	}, {
		'deviceId': xxxxxxxxxx,
		'eventType': 10,
		'timestamp': 1670031576,
		'content': {
			'timeIn': 1670031551,
			'timeOut': 1670031576,
			'autoClear': 5,
			'interval': 5,
			'petWeight': 2654
		},
		'enumEventType': 'pet_out',
		'userId': '100454792',
		'subContent': []
	}, {
.....

Apparently solved by commenting out the break statement in __init.py at line 631 and settinf lst to rls[0] at 626. Don't know if this introduces any regression though.

@zhaoyibo
Copy link
Contributor

I found that def pet_weight(self) will be called twice, which means rls.reverse() will also be called twice.
Just like [1,2,3] -> [3,2,1] -> [1,2,3]

In addition, the content is popped out when calling for the first time, it will not be available the second time. But the petWeight is in the content.

ctx = lst.pop('content', None) or {}

I'm still new to HA and python, and I'm not sure why def pet_weight(self) gets called twice.
I use a copy to avoid this problem.

rls = copy.deepcopy(self.records)

@al-one al-one linked a pull request Jan 14, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants