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

xiaomi sensor added by acpartner can't display battery level #23898

Closed
vaughan-zeng opened this issue May 16, 2019 · 2 comments · Fixed by #23962
Closed

xiaomi sensor added by acpartner can't display battery level #23898

vaughan-zeng opened this issue May 16, 2019 · 2 comments · Fixed by #23962

Comments

@vaughan-zeng
Copy link

homeassistant/components/xiaomi_aqara/init.py

line 295:
def parse_voltage(self, data):

changed to:

def parse_voltage(self, data):
    """Parse battery level data sent by gateway."""
    if 'voltage' not in data and 'battery_voltage' not in data:
        return False

    if 'voltage' in data:
        voltage_key = 'voltage'
    else:
        voltage_key = 'battery_voltage'

    max_volt = 3300
    min_volt = 2800
    voltage = data[voltage_key]
    voltage = min(voltage, max_volt)
    voltage = max(voltage, min_volt)
    percent = ((voltage - min_volt) / (max_volt - min_volt)) * 100
    self._device_state_attributes[ATTR_BATTERY_LEVEL] = round(percent, 1)
    return True
@ghost
Copy link

ghost commented May 18, 2019

Hey there @Danielhiversen, @syssi, mind taking a look at this issue as its been labeled with a integration (xiaomi_aqara) you are listed as a codeowner for? Thanks!

This is a automatic comment generated by codeowners-mention to help ensure issues and pull requests are seen by the right people.

@rytilahti
Copy link
Member

Please use the given template when reporting issues, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants