From 004acc26fba1ef26e14f28104890df1135dd50a9 Mon Sep 17 00:00:00 2001 From: Shulyaka Date: Mon, 2 Nov 2020 15:45:27 +0300 Subject: [PATCH 1/3] Create entity_analog_switch.md --- docs/entity_analog_switch.md | 83 ++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 docs/entity_analog_switch.md diff --git a/docs/entity_analog_switch.md b/docs/entity_analog_switch.md new file mode 100644 index 00000000000..ad70e40e9ab --- /dev/null +++ b/docs/entity_analog_switch.md @@ -0,0 +1,83 @@ +--- +title: Analog Switch Entity +sidebar_label: Analog Switch +--- + +An analog_switch is an entity that allows the user to input an arbitrary number to an integration. Derive entity platforms from [`homeassistant.components.analog_switch.AnalogSwitchEntity`](https://github.com/home-assistant/home-assistant/blob/master/homeassistant/components/analog_switch/__init__.py) + +## Properties + +> Properties should always only return information from memory and not do I/O (like network requests). Implement `update()` or `async_update()` to fetch data. + +| Name | Type | Default | Description +| ---- | ---- | ------- | ----------- +| state | float | **Required** | Current value of the analog switch +| min_value | float | 0 | The minimum accepted value (inclusive) +| max_value | float | 100 | The maximum accepted value (inclusive) +| step | float | **See below** | Defines the resolution of the values, i.e. the smallest increment or decrement +| mode | string | "slider" | Appearance to the user. Either MODE_SLIDER or MODE_BOX +| device_class | string | None | What type of device this. See below for the available device classes. + +Other properties that are common to all entities such as `icon`, `unit_of_measurement`, `name` etc are also applicable. + +The default step value is dynamically chosen based on the range (max - min) values. If the difference between max_value and min_value is greater than 1.0, then the default step is 1.0. If however the range is smaller, then the step is iteratively devided by 10 until it becomes lower than the range. + +## Methods + +### Set value + +Called when the user or automation wants to update the value. + +```python +class MyAnalogSwitch(AnalogSwitchEntity): + # Implement one of these methods. + + def set_value(self, value: float) -> None: + """Update the current value.""" + + async def async_set_value(self, value: float) -> None: + """Update the current value.""" + +``` + +### Increment + +Optional. If not implemented will default to setting a new value based on current `state` and `step` properties. + +```python +class MyAnalogSwitch(AnalogSwitchEntity): + # Implement one of these methods. + + def increment(self) -> None: + """Increment value.""" + + async def async_increment(self) -> None: + """Increment value.""" + +``` + +### Decrement + +Optional. If not implemented will default to setting a new value based on current `state` and `step` properties. + +```python +class MyAnalogSwitch(AnalogSwitchEntity): + # Implement one of these methods. + + def decrement(self) -> None: + """Decrement value.""" + + async def async_decrement(self) -> None: + """Decrement value.""" + +``` + +### Available device classes +Optional. What type of device this. +| Value | Constant | Description +| ----- | -------- | ----------- +| brightness | DEVICE_CLASS_BRIGHTNESS | Entity is a brightness controller +| strength | DEVICE_CLASS_STRENGTH | Entity controlls strength of something +| volume | DEVICE_CLASS_VOLUME | Entity controlls the volume +| speed | DEVICE_CLASS_SPEED | Entity controlls speed +| level | DEVICE_CLASS_LEVEL | Entity controlls the level of something From ce7c47a3f365ca0b72ea2b3d8cb8b29560565bdc Mon Sep 17 00:00:00 2001 From: Shulyaka Date: Mon, 2 Nov 2020 18:36:21 +0300 Subject: [PATCH 2/3] Rename analog_switch into number --- docs/{entity_analog_switch.md => entity_number.md} | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) rename docs/{entity_analog_switch.md => entity_number.md} (82%) diff --git a/docs/entity_analog_switch.md b/docs/entity_number.md similarity index 82% rename from docs/entity_analog_switch.md rename to docs/entity_number.md index ad70e40e9ab..d69dede6eb2 100644 --- a/docs/entity_analog_switch.md +++ b/docs/entity_number.md @@ -1,9 +1,9 @@ --- -title: Analog Switch Entity -sidebar_label: Analog Switch +title: Number Entity +sidebar_label: Number --- -An analog_switch is an entity that allows the user to input an arbitrary number to an integration. Derive entity platforms from [`homeassistant.components.analog_switch.AnalogSwitchEntity`](https://github.com/home-assistant/home-assistant/blob/master/homeassistant/components/analog_switch/__init__.py) +A `number` is an entity that allows the user to input an arbitrary value to an integration. Derive entity platforms from [`homeassistant.components.number.NumberEntity`](https://github.com/home-assistant/home-assistant/blob/master/homeassistant/components/number/__init__.py) ## Properties @@ -11,7 +11,7 @@ An analog_switch is an entity that allows the user to input an arbitrary number | Name | Type | Default | Description | ---- | ---- | ------- | ----------- -| state | float | **Required** | Current value of the analog switch +| state | float | **Required** | Current value of the entity | min_value | float | 0 | The minimum accepted value (inclusive) | max_value | float | 100 | The maximum accepted value (inclusive) | step | float | **See below** | Defines the resolution of the values, i.e. the smallest increment or decrement @@ -29,7 +29,7 @@ The default step value is dynamically chosen based on the range (max - min) valu Called when the user or automation wants to update the value. ```python -class MyAnalogSwitch(AnalogSwitchEntity): +class MyNumber(NumberEntity): # Implement one of these methods. def set_value(self, value: float) -> None: @@ -45,7 +45,7 @@ class MyAnalogSwitch(AnalogSwitchEntity): Optional. If not implemented will default to setting a new value based on current `state` and `step` properties. ```python -class MyAnalogSwitch(AnalogSwitchEntity): +class MyNumber(NumberEntity): # Implement one of these methods. def increment(self) -> None: @@ -61,7 +61,7 @@ class MyAnalogSwitch(AnalogSwitchEntity): Optional. If not implemented will default to setting a new value based on current `state` and `step` properties. ```python -class MyAnalogSwitch(AnalogSwitchEntity): +class MyNumber(NumberEntity): # Implement one of these methods. def decrement(self) -> None: From 3eb13d741a0e8712eeba21fca47aecb0726e211d Mon Sep 17 00:00:00 2001 From: Shulyaka Date: Mon, 2 Nov 2020 18:42:31 +0300 Subject: [PATCH 3/3] Updated as per base PR --- docs/entity_number.md | 44 ------------------------------------------- 1 file changed, 44 deletions(-) diff --git a/docs/entity_number.md b/docs/entity_number.md index d69dede6eb2..e2d681e18b0 100644 --- a/docs/entity_number.md +++ b/docs/entity_number.md @@ -15,8 +15,6 @@ A `number` is an entity that allows the user to input an arbitrary value to an i | min_value | float | 0 | The minimum accepted value (inclusive) | max_value | float | 100 | The maximum accepted value (inclusive) | step | float | **See below** | Defines the resolution of the values, i.e. the smallest increment or decrement -| mode | string | "slider" | Appearance to the user. Either MODE_SLIDER or MODE_BOX -| device_class | string | None | What type of device this. See below for the available device classes. Other properties that are common to all entities such as `icon`, `unit_of_measurement`, `name` etc are also applicable. @@ -39,45 +37,3 @@ class MyNumber(NumberEntity): """Update the current value.""" ``` - -### Increment - -Optional. If not implemented will default to setting a new value based on current `state` and `step` properties. - -```python -class MyNumber(NumberEntity): - # Implement one of these methods. - - def increment(self) -> None: - """Increment value.""" - - async def async_increment(self) -> None: - """Increment value.""" - -``` - -### Decrement - -Optional. If not implemented will default to setting a new value based on current `state` and `step` properties. - -```python -class MyNumber(NumberEntity): - # Implement one of these methods. - - def decrement(self) -> None: - """Decrement value.""" - - async def async_decrement(self) -> None: - """Decrement value.""" - -``` - -### Available device classes -Optional. What type of device this. -| Value | Constant | Description -| ----- | -------- | ----------- -| brightness | DEVICE_CLASS_BRIGHTNESS | Entity is a brightness controller -| strength | DEVICE_CLASS_STRENGTH | Entity controlls strength of something -| volume | DEVICE_CLASS_VOLUME | Entity controlls the volume -| speed | DEVICE_CLASS_SPEED | Entity controlls speed -| level | DEVICE_CLASS_LEVEL | Entity controlls the level of something