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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing device class in netatmo binary sensors #31693

Merged
merged 3 commits into from Feb 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 34 additions & 6 deletions homeassistant/components/netatmo/binary_sensor.py
Expand Up @@ -24,7 +24,10 @@
}
TAG_SENSOR_TYPES = {"Tag Vibration": "vibration", "Tag Open": "opening"}

SENSOR_TYPES = {"NACamera": WELCOME_SENSOR_TYPES, "NOC": PRESENCE_SENSOR_TYPES}
SENSOR_TYPES = {
"NACamera": WELCOME_SENSOR_TYPES,
"NOC": PRESENCE_SENSOR_TYPES,
}

CONF_HOME = "home"
CONF_CAMERAS = "cameras"
Expand Down Expand Up @@ -61,12 +64,28 @@ def get_camera_home_id(data, camera_id):
sensor_types.update(SENSOR_TYPES[camera["type"]])

# Tags are only supported with Netatmo Welcome indoor cameras
if camera["type"] == "NACamera" and data.get_modules(camera["id"]):
sensor_types.update(TAG_SENSOR_TYPES)

for sensor_name in sensor_types:
modules = data.get_modules(camera["id"])
if camera["type"] == "NACamera" and modules:
for module in modules:
for sensor_type in TAG_SENSOR_TYPES:
_LOGGER.debug(
"Adding camera tag %s (%s)",
module["name"],
module["id"],
)
entities.append(
NetatmoBinarySensor(
data,
camera["id"],
home_id,
sensor_type,
module["id"],
)
)

for sensor_type in sensor_types:
entities.append(
NetatmoBinarySensor(data, camera["id"], home_id, sensor_name)
NetatmoBinarySensor(data, camera["id"], home_id, sensor_type)
)
except pyatmo.NoDevice:
_LOGGER.debug("No camera entities to add")
Expand Down Expand Up @@ -115,6 +134,15 @@ def unique_id(self):
"""Return the unique ID for this sensor."""
return self._unique_id

@property
def device_class(self):
"""Return the class of this sensor."""
if self._camera_type == "NACamera":
return WELCOME_SENSOR_TYPES.get(self._sensor_type)
if self._camera_type == "NOC":
return PRESENCE_SENSOR_TYPES.get(self._sensor_type)
return TAG_SENSOR_TYPES.get(self._sensor_type)

@property
def device_info(self):
"""Return the device info for the sensor."""
Expand Down