|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | | -import logging |
6 | | -from typing import Any |
7 | | - |
8 | 5 | import voluptuous as vol |
9 | | -from zengge import zengge |
10 | 6 |
|
11 | | -from homeassistant.components.light import ( |
12 | | - ATTR_BRIGHTNESS, |
13 | | - ATTR_HS_COLOR, |
14 | | - ATTR_WHITE, |
15 | | - PLATFORM_SCHEMA as LIGHT_PLATFORM_SCHEMA, |
16 | | - ColorMode, |
17 | | - LightEntity, |
18 | | -) |
| 7 | +from homeassistant.components.light import PLATFORM_SCHEMA as LIGHT_PLATFORM_SCHEMA |
19 | 8 | from homeassistant.const import CONF_DEVICES, CONF_NAME |
20 | 9 | from homeassistant.core import HomeAssistant |
21 | | -from homeassistant.helpers import config_validation as cv |
| 10 | +from homeassistant.helpers import config_validation as cv, issue_registry as ir |
22 | 11 | from homeassistant.helpers.entity_platform import AddEntitiesCallback |
23 | 12 | from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType |
24 | | -from homeassistant.util import color as color_util |
25 | | - |
26 | | -_LOGGER = logging.getLogger(__name__) |
27 | 13 |
|
28 | 14 | DEVICE_SCHEMA = vol.Schema({vol.Optional(CONF_NAME): cv.string}) |
| 15 | +DOMAIN = "zengge" |
29 | 16 |
|
30 | 17 | PLATFORM_SCHEMA = LIGHT_PLATFORM_SCHEMA.extend( |
31 | 18 | {vol.Optional(CONF_DEVICES, default={}): {cv.string: DEVICE_SCHEMA}} |
32 | 19 | ) |
33 | 20 |
|
34 | 21 |
|
35 | | -def setup_platform( |
| 22 | +def async_setup_platform( |
36 | 23 | hass: HomeAssistant, |
37 | 24 | config: ConfigType, |
38 | 25 | add_entities: AddEntitiesCallback, |
39 | 26 | discovery_info: DiscoveryInfoType | None = None, |
40 | 27 | ) -> None: |
41 | 28 | """Set up the Zengge platform.""" |
42 | | - lights = [] |
43 | | - for address, device_config in config[CONF_DEVICES].items(): |
44 | | - light = ZenggeLight(device_config[CONF_NAME], address) |
45 | | - if light.is_valid: |
46 | | - lights.append(light) |
47 | | - |
48 | | - add_entities(lights, True) |
49 | | - |
50 | | - |
51 | | -class ZenggeLight(LightEntity): |
52 | | - """Representation of a Zengge light.""" |
53 | | - |
54 | | - _attr_supported_color_modes = {ColorMode.HS, ColorMode.WHITE} |
55 | | - |
56 | | - def __init__(self, name: str, address: str) -> None: |
57 | | - """Initialize the light.""" |
58 | | - |
59 | | - self._attr_name = name |
60 | | - self._attr_unique_id = address |
61 | | - self.is_valid = True |
62 | | - self._bulb = zengge(address) |
63 | | - self._white = 0 |
64 | | - self._attr_brightness = 0 |
65 | | - self._attr_hs_color = (0, 0) |
66 | | - self._attr_is_on = False |
67 | | - if self._bulb.connect() is False: |
68 | | - self.is_valid = False |
69 | | - _LOGGER.error("Failed to connect to bulb %s, %s", address, name) |
70 | | - return |
71 | | - |
72 | | - @property |
73 | | - def white_value(self) -> int: |
74 | | - """Return the white property.""" |
75 | | - return self._white |
76 | | - |
77 | | - @property |
78 | | - def color_mode(self) -> ColorMode: |
79 | | - """Return the current color mode.""" |
80 | | - if self._white != 0: |
81 | | - return ColorMode.WHITE |
82 | | - return ColorMode.HS |
83 | | - |
84 | | - def _set_rgb(self, red: int, green: int, blue: int) -> None: |
85 | | - """Set the rgb state.""" |
86 | | - self._bulb.set_rgb(red, green, blue) |
87 | | - |
88 | | - def _set_white(self, white): |
89 | | - """Set the white state.""" |
90 | | - return self._bulb.set_white(white) |
91 | | - |
92 | | - def turn_on(self, **kwargs: Any) -> None: |
93 | | - """Turn the specified light on.""" |
94 | | - self._attr_is_on = True |
95 | | - self._bulb.on() |
96 | | - |
97 | | - hs_color = kwargs.get(ATTR_HS_COLOR) |
98 | | - white = kwargs.get(ATTR_WHITE) |
99 | | - brightness = kwargs.get(ATTR_BRIGHTNESS) |
100 | | - |
101 | | - if white is not None: |
102 | | - # Change the bulb to white |
103 | | - self._attr_brightness = white |
104 | | - self._white = white |
105 | | - self._attr_hs_color = (0, 0) |
106 | | - |
107 | | - if hs_color is not None: |
108 | | - # Change the bulb to hs |
109 | | - self._white = 0 |
110 | | - self._attr_hs_color = hs_color |
111 | | - |
112 | | - if brightness is not None: |
113 | | - self._attr_brightness = brightness |
114 | | - |
115 | | - if self._white != 0: |
116 | | - self._set_white(self.brightness) |
117 | | - else: |
118 | | - assert self.hs_color is not None |
119 | | - assert self.brightness is not None |
120 | | - rgb = color_util.color_hsv_to_RGB( |
121 | | - self.hs_color[0], self.hs_color[1], self.brightness / 255 * 100 |
122 | | - ) |
123 | | - self._set_rgb(*rgb) |
124 | | - |
125 | | - def turn_off(self, **kwargs: Any) -> None: |
126 | | - """Turn the specified light off.""" |
127 | | - self._attr_is_on = False |
128 | | - self._bulb.off() |
129 | | - |
130 | | - def update(self) -> None: |
131 | | - """Synchronise internal state with the actual light state.""" |
132 | | - rgb = self._bulb.get_colour() |
133 | | - hsv = color_util.color_RGB_to_hsv(*rgb) |
134 | | - self._attr_hs_color = hsv[:2] |
135 | | - self._attr_brightness = int((hsv[2] / 100) * 255) |
136 | | - self._white = self._bulb.get_white() |
137 | | - if self._white: |
138 | | - self._attr_brightness = self._white |
139 | | - self._attr_is_on = self._bulb.get_on() |
| 29 | + ir.async_create_issue( |
| 30 | + hass, |
| 31 | + DOMAIN, |
| 32 | + DOMAIN, |
| 33 | + is_fixable=False, |
| 34 | + severity=ir.IssueSeverity.ERROR, |
| 35 | + translation_key="integration_removed", |
| 36 | + translation_placeholders={ |
| 37 | + "led_ble_url": "https://www.home-assistant.io/integrations/led_ble/", |
| 38 | + }, |
| 39 | + ) |
0 commit comments