sopelj / hass-ember-mug-component

Ember Mug Integration for Home Assistant
MIT License
111 stars 4 forks source link

Handle state Unknown #44

Closed sopelj closed 7 months ago

sopelj commented 8 months ago

Handle the state "Unknown'".

Originally posted by @dshokouhi in https://github.com/sopelj/hass-ember-mug-component/issues/43#issuecomment-1897661026

Summary:

ok finally was able to catch it, yes it shows raw state as 0

image

Is the battery low or is it charging?

everytime I have seen it, fully charged sitting on the charger just like it currently is

in fact it looks like as soon as it reported 100% it went to unknown strange.

image

Let me know if you would like more data.

sopelj commented 8 months ago

@dshokouhi thanks for finding this as reproducing! Just out of curiosity, does the state change from "Unknown" to something else when removed from the charging base or only when something else is done to it? We could possibly display this as "Fully Charged" if we can confirm the behaviour.

dshokouhi commented 8 months ago

its definitely not related to fully charged because today this is what I see

image

dshokouhi commented 8 months ago

I even removed it from the charger and put it back on but nothing else updated asides frm teh plugged in state

sopelj commented 8 months ago

Hmm, OK. But it changed to "Unknown" when it reaches 100% charged right?

I thought it might be a state when it was charging on the and reaches full and thus stops charging or starts maintaining that battery level. It probably will probably only show up if now other state is used as they'd likely have precedence.

That screenshot was when you had cold water in it? Or it was supposed to be empty?

dshokouhi commented 8 months ago

But it changed to "Unknown" when it reaches 100% charged right?

It has a few times but not consistently like one would expect.

That screenshot was when you had cold water in it? Or it was supposed to be empty?

it was empty...it basically stayed in the cold state while I hung it upside down to dry after cleaning and then put it on the charge a few hours later. Even now its totally empty but sitting at 100% lol.

sopelj commented 8 months ago

But it changed to "Unknown" when it reaches 100% charged right?

It has a few times but not consistently like one would expect.

Oh, that's super weird. 🤔

That screenshot was when you had cold water in it? Or it was supposed to be empty?

it was empty...it basically stayed in the cold state while I hung it upside down to dry after cleaning and then put it on the charge a few hours later. Even now its totally empty but sitting at 100% lol.

Hmm, OK. That's very strange. I wonder if you're loosing events or if the tumbler really thinks it's still full. It's a more recent device, I wonder if they stopped updating it is often or something to be more efficient. I don't think the states are even displayed in the mobile app, but I haven't checked in a while.

jhemak commented 8 months ago

@dshokouhi thanks for finding this as reproducing! Just out of curiosity, does the state change from "Unknown" to something else when removed from the charging base or only when something else is done to it? We could possibly display this as "Fully Charged" if we can confirm the behaviour.

My mug shows "Unknown" when sitting on the charger fully charged. The state changes to "Empty" if I pick it up from the charger and set it back down without doing anything else to it.

sopelj commented 8 months ago

My mug shows "Unknown" when sitting on the charger fully charged. The state changes to "Empty" if I pick it up from the charger and set it back down without doing anything else to it.

Thanks @jhemak for the info! I think we can safely use that for the behavior whilst it's on the charging pad at least. I'll add it to the next beta. We can see if more cases of Unknown pop up. Out of curiosity, what kind of mug do yu have? As I've never seen this with my Mug 2, but I think I have an older model.

jhemak commented 8 months ago

Thanks! I have a 10oz Mug 2 purchased in Oct '23.

I noticed today it was Unknown while on the charger but still charging. Battery was showing 90% when I noticed this.

sopelj commented 7 months ago

Oh OK. They list two model numbers in their manuals and documentation for Ember Mug 2s:

Ember Mug, 10 oz (CM19, CM21M) Ember Mug, 14 oz (CM19P, CM21L)

Mine is CM19, but I think the newer ones use CM21 and behave slightly differently. Although, a side from the "Unknown" state, no one has mentioned any other differences.

Hmm, that's strange if it came on at 90%. I wonder what it could mean then. 🤔 I don't want to put something incorrect. If we can't be sure, I suppose "Unknown" is still best. Perhaps "Inactive" or "Standby" might work too. They aren't as clear, but it's less scary than unknown and we already know if the device is charged based on the battery level and chargin base so it wouldn't really add anything to say "fully charged" as a state anyway, especially if it's unreliable.

jhemak commented 7 months ago

Mine is CM19. I like the idea of "Standby" in this case. I agree it's less alarming than "Unknown" which suggests there is some sort of problem.

jhemak commented 7 months ago

Today I noticed that after my non-empty mug sat on the charger for several hours, the state changed to "Unknown". At that time, the charge was 43% and the mug was charging. I picked up the mug from the coaster and the state changed from "Unknown" to "Heating", as expected. I think "Standby" during that first phase would have made a lot of sense ... (or perhaps "Charging" given that's what it was doing.)

Later, again after sitting untouched for several hours, the state changed to "Unknown". Now, it was showing 100% charge. I picked up the mug from the coaster and the state changed from "Unknown" to "Heating", again as expected. I think "Standby" or maybe "Fully Charged" as a state would be better than "Unknown" in this case.

sopelj commented 7 months ago

Ok, thanks for the testing! I opted for "Standby" as I think the charging information we already have the battery sensor and the binary sensor for charging. So, I don't think we need to add any extra information to this one, especially if it might be hit or miss. We can always add a new sensor in future though if it can facilitate usage. I've added the state as "standby" in the 0.9.0 release. But we can adjust people find it problematic.

jhemak commented 7 months ago

Awesome! Thank you!!

jhemak commented 7 months ago

Sorry to say, I am getting Unknown while on coaster and charging and once fully charged. That is with the latest production release.

sopelj commented 7 months ago

Oh, sorry. That's weird. Is the "raw state" 0? I did add some translations this morning in the 0.9.1 beta 1. Does that fix it for you?

jhemak commented 7 months ago

Yes, raw state = 0. When I install 0.9.1 beta 1, the integration won't load. Errors like this in the log:

2024-01-27 17:05:20.188 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up ember_mug platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 368, in _async_setup_platform await asyncio.gather(pending) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in async_add_entities await asyncio.gather(tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 672, in _async_add_entity original_icon=entity.icon, ^^^^^^^^^^^ File "/config/custom_components/ember_mug/sensor.py", line 89, in icon state = self.state ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/sensor/init.py", line 524, in state value = self.native_value ^^^^^^^^^^^^^^^^^ File "/config/custom_components/ember_mug/sensor.py", line 100, in native_value return LIQUID_STATE_MAPPING[raw_value].value


KeyError: <LiquidState.STANDBY: 0>
sopelj commented 7 months ago

Oh, sorry about that! I forgot to add it to the mapping of states. Should be fixed in beta 2, but I can't test.

jhemak commented 7 months ago

No need to apologize - you're the one doing all the work! Still getting an error, though, with beta 2:

2024-01-27 19:15:23.383 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform ember_mug Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in async_add_entities await asyncio.gather(*tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 672, in _async_add_entity original_icon=entity.icon, ^^^^^^^^^^^ File "/config/custom_components/ember_mug/sensor.py", line 89, in icon state = self.state ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/sensor/init.py", line 524, in state value = self.native_value ^^^^^^^^^^^^^^^^^ File "/config/custom_components/ember_mug/sensor.py", line 100, in native_value return LIQUID_STATE_MAPPING[raw_value].value


KeyError: <LiquidState.STANDBY: 0>
2024-01-27 19:15:23.392 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up ember_mug platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 368, in _async_setup_platform
await asyncio.gather(*pending)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 672, in _async_add_entity
original_icon=entity.icon,
^^^^^^^^^^^
File "/config/custom_components/ember_mug/sensor.py", line 89, in icon
state = self.state
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 524, in state
value = self.native_value
^^^^^^^^^^^^^^^^^
File "/config/custom_components/ember_mug/sensor.py", line 100, in native_value
return LIQUID_STATE_MAPPING[raw_value].value
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
KeyError: <LiquidState.STANDBY: 0>
sopelj commented 7 months ago

OK, thanks. I really don't know why this is happening. I cannot get it to do that on my end. I added a check and a log entry in case the value is unexpected in beta 3. Could you please try it and see if you see en entry for Value "X" was not found in mapping: Y? Log level for the integration must be set to debug to see this. Thanks!

jhemak commented 7 months ago

Me either ... turns out Beta 2 and 3 are both working now. No errors. Well done!

sopelj commented 7 months ago

Oh perfect thanks! I'll release the version then. I'll close this issue, but feel free to comment or create a new one if other issues arrise or it isn't fixed.