developers.home-assistant/docs/entity_switch.md
Ville Skyttä 770185004b
Code block improvements (#382)
* Use f-strings instead of .format()

* Code block language marker fixes

* Make example code blocks syntactically valid Python

* Run all python code blocks through black

https://github.com/scop/misc/blob/master/black_markdown.py

* Add some missing code block language markers

* Use shell language consistently to mark shell code blocks

* Undo folding of some example dicts

* Remove outdated OrderedDict comments per Python 3.7, replace with plain dict
2020-01-13 21:55:41 +02:00

1.7 KiB

title, sidebar_label
title sidebar_label
Switch Entity Switch

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
is_on boolean Required If the switch is currently on or off.
current_power_w float None The current power usage in W.
today_energy_kwh float None Total energy usage in kWh.
is_standby boolean None Indicate if the device connected to the switch is currently in standby.

Methods

Turn On

Turn the switch on.

class MySwitch(SwitchDevice):
    # Implement one of these methods.

    def turn_on(self, **kwargs) -> None:
        """Turn the entity on."""

    async def async_turn_on(self, **kwargs):
        """Turn the entity on."""

Turn Off

Turn the switch off.

class MySwitch(SwitchDevice):
    # Implement one of these methods.

    def turn_off(self, **kwargs):
        """Turn the entity off."""

    async def async_turn_off(self, **kwargs):
        """Turn the entity off."""

Toggle

Optional. If not implemented will default to checking what method to call using the is_on property.

class MySwitch(SwitchDevice):
    # Implement one of these methods.

    def toggle(self, **kwargs):
        """Toggle the entity."""

    async def async_toggle(self, **kwargs):
        """Toggle the entity."""

Available device classes

Optional. What type of device this. It will possibly map to google device types.

Value Description
outlet Device is an outlet for power.
switch Device is switch for some type of entity.