From 7582ef0b6b03b4b40d61dcb4638798da031472ef Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Sun, 17 Jun 2018 13:41:37 +0200 Subject: [PATCH] Add point about hass in entity checklist (#32) --- docs/creating_platform_code_review.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/creating_platform_code_review.md b/docs/creating_platform_code_review.md index d4be58cc..d38fdba8 100644 --- a/docs/creating_platform_code_review.md +++ b/docs/creating_platform_code_review.md @@ -49,10 +49,11 @@ A checklist of things to do when you're adding a new platform. ### 5. Entity - 1. Extend entity from component, e.g., `class HueLight(Light)` - 2. Do not call `update()` in constructor, use `add_devices(devices, True)` instead. - 3. Do not do any I/O inside properties. Cache values inside `update()` instead. - 4. The state and/or attributes should not contain relative time since something happened. Instead it should store UTC timestamps. + 1. Extend entity from component, e.g., `class HueLight(Light)`. + 2. Avoid passing in `hass` as a parameter to the entity. When the entity has been added to Home Assistant, `hass` will be set on the entity by the helper in entity_platform.py. This means you can access `hass` as `self.hass` inside the entity. + 3. Do not call `update()` in constructor, use `add_devices(devices, True)` instead. + 4. Do not do any I/O inside properties. Cache values inside `update()` instead. + 5. The state and/or attributes should not contain relative time since something happened. Instead it should store UTC timestamps. ### 6. Communication with devices/services