Skip to content

Support calculated UDSK - #89

Open
moritonal wants to merge 3 commits into
sopelj:mainfrom
moritonal:main
Open

moritonal wants to merge 3 commits into
sopelj:mainfrom
moritonal:main

Conversation

@moritonal

Copy link
Copy Markdown

Hi there, first attempt to solve #88

@codecov

codecov Bot commented May 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.37209% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.33%. Comparing base (99dc289) to head (58772a9).

Files with missing lines Patch % Lines
ember_mug/mug.py 84.84% 9 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #89      +/-   ##
==========================================
- Coverage   91.55%   91.33%   -0.23%     
==========================================
  Files          11       11              
  Lines        1066     1142      +76     
  Branches      132      138       +6     
==========================================
+ Hits          976     1043      +67     
- Misses         66       74       +8     
- Partials       24       25       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sopelj sopelj left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, sorry for the delay and thanks for the PR. I have a few questions/requests, but it looks good overall. Would be be possible to rebase with main?
If you would rather, I can make changes based on your PR instead. Thanks!

Comment thread ember_mug/consts.py
LiquidState.COOLING: "Cooling",
LiquidState.HEATING: "Heating",
LiquidState.TARGET_TEMPERATURE: "Perfect",
LiquidState.TARGET_TEMPERATURE: "Ready",

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to this change, but it isn't really pertinent in this PR. It will break things in the Home Assistant integration as well.

Comment thread ember_mug/mug.py
def can_write(self) -> bool:
"""Check if the mug can support write operations."""
return self.data.udsk is not None
return self._session_prepared

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps instead of _session_prepared we could call it _authenticated or something. I think it makes more sense for checks.

Comment thread ember_mug/mug.py
Comment on lines +206 to +217
try:
dsk = await self._read_without_lock(MugCharacteristic.DSK)
except BleakError as error:
logger.debug("Unable to read DSK before pairing: %s", error)
if not await self._pair_for_session():
return False
paired = True
try:
dsk = await self._read_without_lock(MugCharacteristic.DSK)
except BleakError as retry_error:
logger.debug("Unable to read DSK after pairing: %s", retry_error)
return False

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason we need to try to read before pairing? The operation is very quick and errors are ignored. Otherwise we can just call pair in the setup like before and not have to perform each operation twice.

Comment thread ember_mug/mug.py
await self._prepare_session()
await self.subscribe()

async def _read_without_lock(self, characteristic: MugCharacteristic) -> bytearray:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods are a good idea, but I'm not sure they are very useful. They are each only called once with one uuid. We can just call self._client.write_gatt_char or self._client.read_gatt_char in those edge cases

Comment thread ember_mug/mug.py

async def _prepare_session(self) -> bool:
"""Prepare the official Ember DSK/UDSK session when possible."""
self._session_prepared = False

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this just be defined as the default value on the object or in init?

Comment thread ember_mug/mug.py
async def set_udsk_raw(self, udsk: bytes | bytearray) -> None:
"""Write a raw UDSK value."""
await self._write(MugCharacteristic.UDSK, bytearray(udsk))
self.data.udsk = decode_byte_string(udsk)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably replace or be merged with set_udsk and this is the only valid way of doing it.

This branch has not been deployed

No deployments
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 this pull request may close these issues.

2 participants