Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions homeassistant/components/brother/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,40 @@

from __future__ import annotations

import logging

from brother import Brother, SnmpError

from homeassistant.components.snmp import async_get_snmp_engine
from homeassistant.const import CONF_HOST, CONF_TYPE, Platform
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TYPE, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady

from .const import DOMAIN
from .const import (
CONF_COMMUNITY,
DEFAULT_COMMUNITY,
DEFAULT_PORT,
DOMAIN,
SECTION_ADVANCED_SETTINGS,
)
from .coordinator import BrotherConfigEntry, BrotherDataUpdateCoordinator

_LOGGER = logging.getLogger(__name__)

PLATFORMS = [Platform.SENSOR]


async def async_setup_entry(hass: HomeAssistant, entry: BrotherConfigEntry) -> bool:
"""Set up Brother from a config entry."""
host = entry.data[CONF_HOST]
port = entry.data[SECTION_ADVANCED_SETTINGS][CONF_PORT]
community = entry.data[SECTION_ADVANCED_SETTINGS][CONF_COMMUNITY]
printer_type = entry.data[CONF_TYPE]

snmp_engine = await async_get_snmp_engine(hass)
try:
brother = await Brother.create(
host, printer_type=printer_type, snmp_engine=snmp_engine
host, port, community, printer_type=printer_type, snmp_engine=snmp_engine
)
except (ConnectionError, SnmpError, TimeoutError) as error:
raise ConfigEntryNotReady(
Expand All @@ -48,3 +60,22 @@ async def async_setup_entry(hass: HomeAssistant, entry: BrotherConfigEntry) -> b
async def async_unload_entry(hass: HomeAssistant, entry: BrotherConfigEntry) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)


async def async_migrate_entry(hass: HomeAssistant, entry: BrotherConfigEntry) -> bool:
"""Migrate an old entry."""
if entry.version == 1 and entry.minor_version < 2:
new_data = entry.data.copy()
new_data[SECTION_ADVANCED_SETTINGS] = {
CONF_PORT: DEFAULT_PORT,
CONF_COMMUNITY: DEFAULT_COMMUNITY,
}
hass.config_entries.async_update_entry(entry, data=new_data, minor_version=2)

_LOGGER.info(
"Migration to configuration version %s.%s successful",
entry.version,
entry.minor_version,
)

return True
66 changes: 57 additions & 9 deletions homeassistant/components/brother/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,65 @@

from homeassistant.components.snmp import async_get_snmp_engine
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_HOST, CONF_TYPE
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TYPE
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import section
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.service_info.zeroconf import ZeroconfServiceInfo
from homeassistant.util.network import is_host_valid

from .const import DOMAIN, PRINTER_TYPES
from .const import (
CONF_COMMUNITY,
DEFAULT_COMMUNITY,
DEFAULT_PORT,
DOMAIN,
PRINTER_TYPES,
SECTION_ADVANCED_SETTINGS,
)

DATA_SCHEMA = vol.Schema(
{
vol.Required(CONF_HOST): str,
vol.Optional(CONF_TYPE, default="laser"): vol.In(PRINTER_TYPES),
vol.Required(SECTION_ADVANCED_SETTINGS): section(
vol.Schema(
{
vol.Required(CONF_PORT, default=DEFAULT_PORT): int,
vol.Required(CONF_COMMUNITY, default=DEFAULT_COMMUNITY): str,
},
),
{"collapsed": True},
),
}
)
ZEROCONF_SCHEMA = vol.Schema(
{
vol.Optional(CONF_TYPE, default="laser"): vol.In(PRINTER_TYPES),
vol.Required(SECTION_ADVANCED_SETTINGS): section(
vol.Schema(
{
vol.Required(CONF_PORT, default=DEFAULT_PORT): int,
vol.Required(CONF_COMMUNITY, default=DEFAULT_COMMUNITY): str,
},
),
{"collapsed": True},
),
}
)
RECONFIGURE_SCHEMA = vol.Schema(
{
vol.Required(CONF_HOST): str,
vol.Required(SECTION_ADVANCED_SETTINGS): section(
vol.Schema(
{
vol.Required(CONF_PORT, default=DEFAULT_PORT): int,
vol.Required(CONF_COMMUNITY, default=DEFAULT_COMMUNITY): str,
},
),
{"collapsed": True},
),
}
)
RECONFIGURE_SCHEMA = vol.Schema({vol.Required(CONF_HOST): str})


async def validate_input(
Expand All @@ -35,7 +79,12 @@ async def validate_input(

snmp_engine = await async_get_snmp_engine(hass)

brother = await Brother.create(user_input[CONF_HOST], snmp_engine=snmp_engine)
brother = await Brother.create(
user_input[CONF_HOST],
user_input[SECTION_ADVANCED_SETTINGS][CONF_PORT],
user_input[SECTION_ADVANCED_SETTINGS][CONF_COMMUNITY],
snmp_engine=snmp_engine,
)
await brother.async_update()

if expected_mac is not None and brother.serial.lower() != expected_mac:
Expand All @@ -48,6 +97,7 @@ class BrotherConfigFlow(ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Brother Printer."""

VERSION = 1
MINOR_VERSION = 2

def __init__(self) -> None:
"""Initialize."""
Expand Down Expand Up @@ -126,13 +176,11 @@ async def async_step_zeroconf_confirm(
title = f"{self.brother.model} {self.brother.serial}"
return self.async_create_entry(
title=title,
data={CONF_HOST: self.host, CONF_TYPE: user_input[CONF_TYPE]},
data={CONF_HOST: self.host, **user_input},
)
return self.async_show_form(
step_id="zeroconf_confirm",
data_schema=vol.Schema(
{vol.Optional(CONF_TYPE, default="laser"): vol.In(PRINTER_TYPES)}
),
data_schema=ZEROCONF_SCHEMA,
description_placeholders={
"serial_number": self.brother.serial,
"model": self.brother.model,
Expand Down Expand Up @@ -160,7 +208,7 @@ async def async_step_reconfigure(
else:
return self.async_update_reload_and_abort(
entry,
data_updates={CONF_HOST: user_input[CONF_HOST]},
data_updates=user_input,
)

return self.async_show_form(
Expand Down
7 changes: 7 additions & 0 deletions homeassistant/components/brother/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@
PRINTER_TYPES: Final = ["laser", "ink"]

UPDATE_INTERVAL = timedelta(seconds=30)

SECTION_ADVANCED_SETTINGS = "advanced_settings"

CONF_COMMUNITY = "community"

DEFAULT_COMMUNITY = "public"
DEFAULT_PORT = 161
45 changes: 44 additions & 1 deletion homeassistant/components/brother/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,44 @@
"type": "Type of the printer"
},
"data_description": {
"host": "The hostname or IP address of the Brother printer to control."
"host": "The hostname or IP address of the Brother printer to control.",
"type": "Brother printer type: ink or laser."
},
"sections": {
"advanced_settings": {
"name": "Advanced settings",
"data": {
"port": "[%key:common::config_flow::data::port%]",
"community": "SNMP Community"
},
"data_description": {
"port": "The SNMP port of the Brother printer.",
"community": "A simple password for devices to communicate to each other."
}
}
}
},
"zeroconf_confirm": {
"description": "Do you want to add the printer {model} with serial number `{serial_number}` to Home Assistant?",
"title": "Discovered Brother Printer",
"data": {
"type": "[%key:component::brother::config::step::user::data::type%]"
},
"data_description": {
"type": "[%key:component::brother::config::step::user::data_description::type%]"
},
"sections": {
"advanced_settings": {
"name": "Advanced settings",
"data": {
"port": "[%key:common::config_flow::data::port%]",
"community": "SNMP Community"
},
"data_description": {
"port": "The SNMP port of the Brother printer.",
"community": "A simple password for devices to communicate to each other."
}
}
}
},
"reconfigure": {
Expand All @@ -25,6 +55,19 @@
},
"data_description": {
"host": "[%key:component::brother::config::step::user::data_description::host%]"
},
"sections": {
"advanced_settings": {
"name": "Advanced settings",
"data": {
"port": "[%key:common::config_flow::data::port%]",
"community": "SNMP Community"
},
"data_description": {
"port": "The SNMP port of the Brother printer.",
"community": "A simple password for devices to communicate to each other."
}
}
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/derivative/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/derivative",
"integration_type": "helper",
"iot_class": "calculated"
"iot_class": "calculated",
"quality_scale": "internal"
}
3 changes: 2 additions & 1 deletion homeassistant/components/generic_thermostat/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"dependencies": ["sensor", "switch"],
"documentation": "https://www.home-assistant.io/integrations/generic_thermostat",
"integration_type": "helper",
"iot_class": "local_polling"
"iot_class": "local_polling",
"quality_scale": "internal"
}
25 changes: 18 additions & 7 deletions homeassistant/components/homee/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dataclasses import dataclass

from pyHomee.const import AttributeChangedBy, AttributeType
from pyHomee.model import HomeeAttribute
from pyHomee.model import HomeeAttribute, HomeeNode

from homeassistant.components.alarm_control_panel import (
AlarmControlPanelEntity,
Expand All @@ -17,7 +17,7 @@

from . import DOMAIN, HomeeConfigEntry
from .entity import HomeeEntity
from .helpers import get_name_for_enum
from .helpers import get_name_for_enum, setup_homee_platform

PARALLEL_UPDATES = 0

Expand Down Expand Up @@ -60,21 +60,32 @@ def get_supported_features(
return supported_features


async def async_setup_entry(
hass: HomeAssistant,
async def add_alarm_control_panel_entities(
config_entry: HomeeConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
nodes: list[HomeeNode],
) -> None:
"""Add the Homee platform for the alarm control panel component."""

"""Add homee alarm control panel entities."""
async_add_entities(
HomeeAlarmPanel(attribute, config_entry, ALARM_DESCRIPTIONS[attribute.type])
for node in config_entry.runtime_data.nodes
for node in nodes
for attribute in node.attributes
if attribute.type in ALARM_DESCRIPTIONS and attribute.editable
)


async def async_setup_entry(
hass: HomeAssistant,
config_entry: HomeeConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Add the homee platform for the alarm control panel component."""

await setup_homee_platform(
add_alarm_control_panel_entities, async_add_entities, config_entry
)


class HomeeAlarmPanel(HomeeEntity, AlarmControlPanelEntity):
"""Representation of a Homee alarm control panel."""

Expand Down
28 changes: 20 additions & 8 deletions homeassistant/components/homee/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""The Homee binary sensor platform."""

from pyHomee.const import AttributeType
from pyHomee.model import HomeeAttribute
from pyHomee.model import HomeeAttribute, HomeeNode

from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
Expand All @@ -14,6 +14,7 @@

from . import HomeeConfigEntry
from .entity import HomeeEntity
from .helpers import setup_homee_platform

PARALLEL_UPDATES = 0

Expand Down Expand Up @@ -152,23 +153,34 @@
}


async def async_setup_entry(
hass: HomeAssistant,
async def add_binary_sensor_entities(
config_entry: HomeeConfigEntry,
async_add_devices: AddConfigEntryEntitiesCallback,
async_add_entities: AddConfigEntryEntitiesCallback,
nodes: list[HomeeNode],
) -> None:
"""Add the Homee platform for the binary sensor component."""

async_add_devices(
"""Add homee binary sensor entities."""
async_add_entities(
HomeeBinarySensor(
attribute, config_entry, BINARY_SENSOR_DESCRIPTIONS[attribute.type]
)
for node in config_entry.runtime_data.nodes
for node in nodes
for attribute in node.attributes
if attribute.type in BINARY_SENSOR_DESCRIPTIONS and not attribute.editable
)


async def async_setup_entry(
hass: HomeAssistant,
config_entry: HomeeConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Add the homee platform for the binary sensor component."""

await setup_homee_platform(
add_binary_sensor_entities, async_add_entities, config_entry
)


class HomeeBinarySensor(HomeeEntity, BinarySensorEntity):
"""Representation of a Homee binary sensor."""

Expand Down
Loading
Loading